% Integration of some simple polynomials

hold off
for i = 1:6
   err_thint(i) = thint(@(x) x.^2, 0, 1, 10^(i))*3 - 1;
   err_midpt(i) = midpoint1(@(x) x.^2, 0, 1, 10^(i))*3 - 1;
end
semilogy(1:6, abs(err_midpt), 'k-+', 1:6, abs(err_thint), 'k-o');
hold on

for i = 1:6
   err_thint(i) = thint(@(x) x.^3, 0, 1, 10^(i))*4 - 1;
   err_midpt(i) = midpoint1(@(x) x.^3, 0, 1, 10^(i))*4 - 1;
end
semilogy(1:6, abs(err_midpt), 'b-+', 1:6, abs(err_thint), 'b-o');

for i = 1:6
   err_thint(i) = thint(@(x) x.^4, 0, 1, 10^(i))*5 - 1;
   err_midpt(i) = midpoint1(@(x) x.^4, 0, 1, 10^(i))*5 - 1;
end
semilogy(1:6, abs(err_midpt), 'g-+', 1:6, abs(err_thint), 'g-o');

for i = 1:6
   err_thint(i) = thint(@(x) x.^7, 0, 1, 10^(i))*8 - 1;
   err_midpt(i) = midpoint1(@(x) x.^7, 0, 1, 10^(i))*8 - 1;
end
semilogy(1:6, abs(err_midpt), 'r-+', 1:6, abs(err_thint), 'r-o');


legend('midpoint, y = x^2', 'thint, y = x^2', ...
       'midpoint, y = x^3', 'thint, y = x^3', ...
       'midpoint, y = x^4', 'thint, y = x^4',...
       'midpoint, y = x^7', 'thint, y = x^7');
ylabel('log10 absolute error','fontsize',16)
xlabel('log10 number of steps','fontsize',16)
title('Integrating polynomials','fontsize',20)
hold off
