clc
close all
clear all

% m = [1:500:10000];
% for j=1:4
% for i = 1:length(m)
%     [ Int(i), errorG1(i),exact] = simpson([-4,4],m(i),j);
% end
% 
% figure(j)
% subplot(3,1,1)
% plot(m,errorG1)
% title('Absolute error vs number of subinterval iterations')
% ylabel('Absolute error')
% xlabel('Number of subinterval iterations')
% 
% subplot(3,1,2)
% plot(m,log(errorG1))
% title('Logarithmic error vs number of subinterval iterations')
% ylabel('Logarithmic error')
% xlabel('Number of subinterval iterations')
% 
% subplot(3,1,3)
% plot(m,errorG1./exact)
% title('Relative error vs number of subinterval iterations')
% ylabel('Relative error')
% xlabel('Number of subinterval iterations')
% 
% end

m = [1:500:10000];
for j=1:4
    for i = 1:length(m)
        [I(i),E(i),exact] = hw2(2, [-4, 4], j,m(i));
    end

    figure(j)
    subplot(3,1,1)
    plot(m,E)
    title('Absolute error vs number of subinterval iterations')
    ylabel('Absolute error')
    xlabel('Number of subinterval iterations')

    subplot(3,1,2)
    plot(m,log(E))
    title('Logarithmic error vs number of subinterval iterations')
    ylabel('Logarithmic error')
    xlabel('Number of subinterval iterations')

    subplot(3,1,3)
    plot(m,E./exact)
    title('Relative error vs number of subinterval iterations')
    ylabel('Relative error')
    xlabel('Number of subinterval iterations')

end

% m = [1:500:10000];
% for j=1:4
% for i = 1:length(m)
%     [ Int(i), errorG2(i),exact] = trapezoid([-4,4],m(i),j);
% end

% figure(j)
% subplot(3,1,1)
% plot(m,errorG2)
% title('Absolute error vs number of subinterval iterations')
% ylabel('Absolute error')
% xlabel('Number of subinterval iterations')
% 
% 
% subplot(3,1,2)
% plot(m,log(errorG2))
% title('Logarithmic error vs number of subinterval iterations')
% ylabel('Logarithmic error')
% xlabel('Number of subinterval iterations')
% 
% subplot(3,1,3)
% plot(m,errorG2./exact)
% title('Relative error vs number of subinterval iterations')
% ylabel('Relative error')
% xlabel('Number of subinterval iterations')
% 
% 
% end