% Romberg Integration
% Employing the Composite Trapezoidal Rule
% plus Richardson's Extraploation

% Input endpoints
a=0;
b=pi;
% Input number of subintervals 
n=5;

h=(b-a);
R(1,1)=h*(intf2(a)+intf2(b))/2;
display(R(1,1))

for i=2:n
   k=1:2^(i-2);
   R(2,1)=(R(1,1)+h*sum(intf2(a+(k-0.5)*h)))/2;
   for j=2:i
      R(2,j)=R(2,j-1)+(R(2,j-1)-R(1,j-1))/(4^(j-1)-1);
   end
   display(R(2,:))
   h=h/2;
   for j=1:i
      R(1,j)=R(2,j);
   end
end

