You are on page 1of 1

Program For Simpson 1/3 Rule

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 :

enter lower limit x0=0


enter upper limit xn=3*pi/20
enter no of strips n=6
the value of integral by simpson 1/3 rule=0.689226>>

SOLVER :
A=quad('(1+2*sin(x))',0,3*pi/20)

A=

0.6892

You might also like