Anda di halaman 1dari 6

Experiment No:- 08

Name of the Experiment:MATLAB program for trapezoidal rule, Simpsons 1/3 rule and Simpsons 3/8 rule.
Objectives:Objectives if this experiment are1. To perform numerical integration using different methods .
2. To compare the accuracy of those methods.
Theory:Numerical integration is one of the most useful mathematical tools used in different
sectors of our work field. The general problem of numerical integration may be stated as
follows- Given a set of data points (x 0, y0), (x1, y1), .(xn, yn) of a function y = f(x), where
f(x) is not known explicitly, it is required to compute the value of the definite integralb

I = y dx
a

Which can be treated as the area under the curve y=f(x) enclosed between the limits
x=ax=b . This is the basic theme of integration. There are various techniques of
numerical integration among which 3 techniques are described briefly belowTrapezoidal rule:Trapezoidal rule is the simplest forms of numerical integration which works with
two data points taken at a time. Those points are joined as a straight line which forms
trapezoidal and area under those points are measured. Then next two data points are taken
and same procedures are applied. The general integral form i.e. the area under all the data
points can be difined by the following eqationS= ( f1/2 + f2 + f3 + ..+ fn+1)*h
where h is the distance between two data points.
Using this equation we will get the value of the integral.
Simpsons 1/3 rule:Simpsons 1/3 rule is a popular numerical integration technique. It is based on
approximating the function f(x) by fitting the quadratics through sets of three points. A
parabolla is formed due to joining three points. All the points are joined in this way and the
area under the data points are measured by the following equation-

S= h/3*( f1 + 4f2 + 2f3+ 4f4 + 2f3 +..+ fn+1)


Where h is the distance between two data points. The term 1/3 multiplied with h is the reason
of calling it 1/3 rule.
Simpsons 3/8 rule:Simpsons 3/8 rule is the extension of Simpsons 1/3 rule. It is based on joining
four data points so it can be exact for f(x) of degree 3. Error in Simpsons 3/8 rule is more
than Simpsons 1/3 rule thats why this is not so used. The integral of given data points using
Simpsons 3/8 rule can be determined from the following equationS= 3h/8* ( f1+ 3f2+ 3f3+ 2f4+ 3f5+ 3f6+ 2f7++ fn+1)
where h is the distance between two data points. The term 3/8 multiplied with h is the reason
of calling it 3/8 rule.
MATLAB program :MATLAB program for the above mentioned 3 numerical techniques are given
belowMATLAB program for Trapezoidal rule:-

clc
clear all
n=input('total data - 1 = ');
for i= 1:(n+1)
x(i)=input('x= ');
y(i)=input('y= ');
end
h= x(2)-x(1);
s=(y(1)+y(n+1))/2;
for j= 2:n
s=s+y(j);
end
integral= s*h

Output:total data - 1 = 4
x= .25
y= .2474
x= .26
y= .2571
x= .27
y= .2667
x= .28
y= .2764
x= .29
y= .2860

integral =
0.0107

MATLAB program for Simpsons 1/3 rule:clc


clear all
n=input('total data - 1 = ');
for i= 1:(n+1)
x(i)=input('x= ');
y(i)=input('y= ');
end
h= x(2)-x(1);
s=y(1)+y(n+1);
for i= 2:2:n
s=s+4*y(i);
end
for i=3:2:(n-1)
s=s+2*y(i);
end
integral= s*(h/3)

Output:total data - 1 = 4
x= .25
y= .2474
x= .26
y= .2571
x= .27
y= .2667
x= .28
y= .2764
x= .29
y= .2860
integral =
0.0107

MATLAB program for Simpsons 1/3 rule:clc


clear all
n=input('total data-1 = ');
for i= 1:(n+1)
x(i)=input('x= ');
y(i)=input('y= ');
end
h= x(2)-x(1);
s=y(1)+y(n+1);
for i= 2:3:n
s=s+3*y(i);
end
for i=3:3:(n-2)
s=s+3*y(i);
end
for i=4:3:(n-1)
s=s+2*y(i);
end

integral= s*(3*h/8)
Output:-

total data-1 = 8
x= 0
y= 1
x= .125
y= .8889
x= .25
y= .8
x= .375
y= .7273
x= .5
y= .6667
x= .625
y= .6154
x= .75
y= .5714
x= .875
y= .533
x= 1
y= .5

integral =

0.6848

Conclusion:From the above discussion and program we can say that without knowing the
functions we can find out the integral of a set of data points. Above three numerical technique
Simpsons 1/3 rule gives more accurate result than the others. Though here the result using
trapezoidal and Simpsons 1/3 rule is same but the previous statement will be easily visible if
the number of data points is more.