
function demo_midpoint_composta

f=@(x) (sin(x)).^2;

estremi=[0 pi/3];

for k=1:3
   N=100^k;
   S(k)=midpoint_composta(f,N,estremi);
   fprintf('\n \t k: %1.0f,  S(k): %1.15e',k,S(k));
end

err(1)=abs(S(3)-S(1));
err(2)=abs(S(3)-S(2));

fprintf('\n')

fprintf('\n \t err(1): %1.3e',err(1));
fprintf('\n \t err(2): %1.3e',err(2));

fprintf('\n')

% NOTA:
% Una primitiva di (sin(x)).^2 e' x/2 - sin(2*x)/4.
% Il risultato esatto e' pi/6-3^(1/2)/8=3.070924246521891e-01.

% >> demo_midpoint_composta
% 
%  	 k: 1,  S(k): 3.070884675052023e-01
%  	 k: 2,  S(k): 3.070924242564793e-01
%  	 k: 3,  S(k): 3.070924246521494e-01
% 
%  	 err(1): 3.957e-06
%  	 err(2): 3.957e-10
% >> 