You are on page 1of 1

PROGRAM ON SIMPSON'S 1/3 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=exp(x0); yn=exp(xn); while(mod(n,2)~=0) n=input ('\n Enter the value of n again:'); end answ=0; for(i=1:n-1) if(mod(i,2)~=0) answ=answ+(4*(exp(x0+(i*h)))); else answ=answ+(2*(exp(x0+(i*h)))); end end answ1=(y0+yn); area=(h/3)*(answ1+answ); fprintf('\n Area is=%f',area); OUTPUT: Enter the initial limit:0 Enter the final limit:4 Enter the value of n:4 Area is=53.863846

You might also like