%problem 11.7
%Integrate 2^x from x=0 to x=4
a=0;
b=4;
n=20;
h=(b-a)/n;
xx=0:h:4;
yy=2.^xx;
%method 1 Trapezoidal rule
sum1=h/2*(yy(1)+yy(n+1));
for i=2:n
   sum1=sum1+2*h/2*yy(i);
end
%simpson's 1/3 rule
sum2=h/3*(yy(1)+yy(n+1));
for i=2:2:n
   sum2=sum2+4*h/3*yy(i);
end
for i=3:2:n-1
   sum2=sum2+2*h/3*yy(i);
end
disp(' Trapezoidal rule Simpson 1/3 rule')
[sum1 sum2]