
clc, clear

a = 0;
b = 1;

h = b-a;
T(1) = h/2*(1+sin(b)/b);

fprintf('n\t   T_2n\t\t |T_2n - T_n| \n1\t%.9f\n',T(1));


for n = 1:15
    
    hn = h/2^(n-1);
    xn = a + ( 0:2^(n-1)-1 )*hn + hn/2;
    T(n+1) = T(n)/2 + hn/2 * sum( sin(xn)./xn );
    fprintf('%d\t%.9f\t  %.9f\n',2^n,T(n+1),abs(T(n+1)-T(n)) );
    
    if n>=2 && abs( T(n+1)-T(n) ) <= 1e-7
        break
    end    
    
end


