%problem A11.1
%Pipe flow rate

n=4;
h=0.1;
%xx=r    xy=V
xx=[0 .1 .2 .3 .4];
%using V data
xy=[1.0 .99 .96 .91 .84];
%or using v=1-r^2
xy=1-xx.^2;
yy=2*pi*xx.*xy;
%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]