Professional Documents
Culture Documents
f=inline('(1+2*sin(x))');
x0=input('\n enter lower limit x0=');
xn=input('\n enter upper limit xn=');
n=input('\n enter no of strips n=');
while(mod(n,2)~=0)
fprintf('\n no.of strips are not multiple of 2');
n=input('\n enter no. of strips again n=');
end
h=(xn-x0)/n;
area=0;
while(x0<xn)
area=area+h/3*(f(x0)+4*f(x0+h)+f(x0+2*h));
x0=x0+2*h;
end
fprintf('\n the value of integral by simpson 1/3 rule=%f',area);
Output :
SOLVER :
A=quad('(1+2*sin(x))',0,3*pi/20)
A=
0.6892