You are on page 1of 1

PROGRAM ON SIMPSON'S 3/8 RULE:

clc;
x0=input('\n Enter the initial limit:');
xn=input('\n Enter the final limit:');
n=input ('\n Enter the value of n:');
h=(xn-x0)/n;
y0=4*x0-1;
yn=4*xn-1;
while(mod(n,3)~=0)
n=input ('\n Enter the value of n again:');
end
answ=0;
answ1=0;
for(i=1:n-1)
if(mod(i,3)~=0)
answ=answ+(3*(4*(x0+i*h)-1));
else
answ1=answ1+(2*(4*(x0+i*h)-1));
end
end
answ2=(y0+yn);
area=((3/8)*h)*(answ2+answ1+answ);
fprintf('\n Area is=%f',area);
OUTPUT:
Enter the initial limit:1
Enter the final limit:4
Enter the value of n:6
Area is=27.000000

You might also like