O = '---- Range of step sizes using midpoint2 (parabola) ---- = O'
Nfor = 1e1;
pow = [1,2,3,4,5,6,7];
Nsteps = (10.^pow).*Nfor
Ntrials = numel(pow)
for i = 1:Ntrials
   t0 = cputime;
   errors(i) = midpoint2(@parabola, 0, 1, Nfor, 10^pow(i)) - 1/3;
   error = errors(i)
   execution_time = cputime - t0
end
hold off
plot(log10(Nsteps), log10(abs(errors)), 'o-k');
xlabel('log10 number of steps', 'fontsize', 16);
ylabel('log10 absolute error', 'fontsize', 16);
title('midpoint rule integration', 'fontsize', 18);
hold on


O = '---- Range of step sizes using midpoint2 (improper) ---- = O'
for i = 1:Ntrials
   t0 = cputime;
   errors(i) = midpoint2(@improper, 0, 1, Nfor, 10^pow(i)) - 2;
   error = errors(i)
   execution_time = cputime - t0
end
plot(log10(Nsteps), log10(abs(errors)), '+-b');


O = '---- Range of step sizes using midpoint2 (circle) ---- = O'
for i = 1:Ntrials
   t0 = cputime;
   errors(i) = midpoint2(@circle, 0, 1, Nfor, 10^pow(i)) - pi/4;
   error = errors(i)
   execution_time = cputime - t0
end
plot(log10(Nsteps), log10(abs(errors)), '^-g');

legend('parabola','improper','circle');

hold off