Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Faisal
1. University of Engineering & Technology LHR
(FAISALABAD CAMPUS) by FAISAL SAEED
Trapezoidal Rule
function trapezoidalrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=0;
for i=x0:h:xn
if(i==x0 || i==xn)
continue;
end
sum=sum +f(i);
end
sum=sum*2;
trapezoidal=h/2*(f(x0)+f(xn)+sum)
end
2. Output:-
Simpsons 1/3 Rule
function simpsonsrule
syms count;
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=f(x0)+f(xn)+4*f(xn-h);
for count=1:2:n-3;
sum=sum+4*f(x0+count*h)+2*f(x0+(count+1)*h);
A=h*sum/3;
end
fprintf('integration is %d n ',A);
3. end
Output:-
Simpsons 3/8 Rule
function simpsonsrule
syms count;
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=f(x0)+f(xn);
for count=1:n-1;
if (mod(count,3)==0)
sum=sum+2*f(x0+count*h);
else
sum=sum+3*f(x0+count*h);
end
end
A=sum*3*h/8;