You are on page 1of 33

ME 261

Numerical Analysis

Lecture-3:
Numerical Integration

Md. Masudur Rahman


Lecturer
Department of Mechanical Engineering
Sonargaon University
Lecture-3: Numerical Integration 2
Graphical Representation of Integral

Integral = area under the curve i.e.


b

 f ( x)dx  area of the shaded region


a

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 3
Newton-Cotes Integration Formulas
The Newton-Cotes formulas are the most common numerical integration schemes.
They are based on the strategy of replacing a complicated function or tabulated data
with an approximating function that is easy to integrate

[where n is the order of the polynomial.]

f1 (x): linear (1st order) f2 (x): quadratic (2nd order) f3 (x): Cubic ( 3rd order)
Trapezoidal Rule Simpson’s 1/3-Rule Simpson’s 3/8-Rule
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 4
The Trapezoidal Rule
The trapezoidal rule is the first of the Newton-Cotes closed integration formulas. It
corresponds to the case where the polynomial fn(x) is first-order (i.e. equation of a
straight line). So, for trapezoidal rule,
b b
I   f ( x)dx   f1 ( x)dx
a a

We know that a straight line can be represented as follows


f (b)  f (a )
f1 ( x)  f (a )  ( x  a ) so,
ba
b
b
 f (b)  f (a )   f (b)  f (a ) x 2 
I    f (a)  ( x  a ) dx   xf (a )  (  ax) 
a ba   ba 2 a
 f (b)  f (a ) b 2 f (b)  f (a ) a 2 
 bf (a )  (  ab)  af (a )  (  a2 )
 ba 2 ba 2 
 f (b)  f (a ) b 2 a2   f (b)  f (a ) 2 
 (  ab  )  f (a )(b  a )    (b  2ba  a 2 )  f (a )(b  a ) 
 ba 2 2   2(b  a ) 
f (b)  f (a ) (b  a )
 (b  a )  f (a )(b  a )   f (b)  f (a)  2 f (a) 
2 2
(b  a )
I   f (b)  f (a) [This is called Trapezoidal Rule]
2
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 5
Graphical Depiction of Trapezoidal Rule

FIGURE
(a) The formula for computing
the area of a trapezoid: height
times the average of the bases.
(b) For the trapezoidal rule, the
concept is the same but the
trapezoid is on its side.

According to Trapezoidal Rule


(b  a )
I  f (b)  f (a)
2
h
  f (b)  f (a ) 
2
where, h = Width of the Trapezium

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 6
Simple Example of Trapezoidal Rule
Find the integral of the following function from x = 0 to 0.8 using a single
application trapezoidal rule. Also find the absolute and relative errors.
f ( x)  0.2  25 x  200 x 2  675 x 3  900 x 4  400 x 5

Solution
The function values
f (a )  f (0)  0.2  25(0)  200(0) 2  675(0)3  900(0) 4  400(0)5  0.2
f (b)  f (0.8)  0.2  25(0.8)  200(0.8) 2  675(0.8)3  900(0.8) 4  400(0.8)5  0.232
Now using Trapezoidal rule we get,
ba
I approx.   f (b)  f (a)
2
0.8  0
 (0.232  0.2)
2
 0.1728

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 7
Simple Example of Trapezoidal Rule
Using Analytical approach we get,
b 0.8
I actual   f ( x)dx   (0.2  25 x  200 x 2
 675 x 3
 900 x 4
 400 x 5
)dx
a 0
0.8
 25 x 2
200 x 675 x 3
900 x 400 x 
4 5 6
 0.2 x      
 2 3 4 5 6 0
 25(0.8) 2 200(0.8)3 675(0.8) 4 900(0.8)5 400(0.8)6 
 0.2(0.8)       0
 2 3 4 5 6 
 1.640533
so, Absolute Error, Ea  I actual  I approx.
 1.640533  0.1728  1.467733
I actual  I approx.
and Relative Rrror, E r   100%
I actual
1.467733
  100%  89.5%
1.640533

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 8
Error of the Trapezoidal Rule
Graphical depiction of the use of a single application trapezoidal rule to approximate
the integral of the following function from x = 0 to 0.8
f ( x)  0.2  25 x  200 x 2  675 x 3  900 x 4  400 x 5

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 9
The Multiple-Application Trapezoidal Rule
One way to improve the accuracy of the trapezoidal rule is to divide the integration interval
from a to b into a number of segments and apply the method to each segment. The areas of
individual segments can then be added to yield the integral for the entire interval. The
resulting equations are called multiple-application, or composite, integration formulas.

FIGURES
Illustration of the multiple-
application trapezoidal rule.

(a) Two segments,


(b) three segments,
(c) four segments, and
(d) five segments.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 10
General Format of Multiple-Application Trapezoidal Rule

Let, there are n + 1 equally spaced base points (x0, x1, x2, . . . , xn). Consequently, there
are n segments of equal width.
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 11
General Format of Multiple-Application Trapezoidal Rule
Now the width of each segment :
ba
h  x1  x0  x2  x1                xn  xn 1
n
If a and b are designated as x0 and xn , respectively, the total integral can be
represented as
xn x1 x2 xn

I  f ( x)dx   f ( x)dx   f ( x)dx           


xo xo x1 xn 1
f ( x)dx

Substituting the trapezoidal rule for each integral yields


x1  x0 x x x x
I  f ( x1 )  f ( x0 )  2 1  f ( x2 )  f ( x1 )       n n 1  f ( xn )  f ( xn 1 ) 
2 2 2
h h h
  f ( x1 )  f ( x0 )    f ( x2 )  f ( x1 )         f ( xn )  f ( xn 1 ) 
2 2 2
or, grouping terms,
h n 1

I   f ( x0 )  2 f ( xi )  f ( xn ) 
2 i 1 
Which is the general form of Multiple - Application Trapezoidal Rule
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 12
Example-1
Evaluate the following integral (a) using multiple-application trapezoidal rule, with
n = 4. (b) analytically; (c) Also Find the absolute and relative errors.

2
I   (8  4cos x)dx
0
Solution :

Here, n  4, a  x0  0 and b  xn  x4  , f ( x)  8  4cos( x).
2

0
ba 2 
h   
n 4 8
n xn=xn-1 +h (n=1,2,3,4) f(xn)
0 0 12
1 π/8 11.6955
2 π/4 10.8284
3 3π/8 9.53073
4 π/2 8
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 13
Example-1
Now using Multiple application Trapezoidal Rule with n=4, we get
n f(xn)

2
h
I approx.   (8  4cos x)dx   f ( x0 )  2 f ( x1 )  2 f ( x2 )  2 f ( x3 )  f ( x4 )  0 12
0 2 1 11.6955

2 10.8284
 8 12  2  11.6955  2  10.8284  2  9.53073  8
2 3 9.5307
 16.5149
Using analitical approach we get, 4 8

2 
I actual   (8  4cos x)dx  8 x  4sin x 02
0

   
 8   4sin( )  0   16.5664
 2 2 
So, Absolute Error, Ea  I actual  I approx.  16.5664  16.5149  0.0515
I actual  I approx. 0.0515
and Relative Rrror, E r   100%   100%  0.31%
I actual 16.5664

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 14
The Simpson’s 1/3 Rule
The Simpson’s 1/3 rule is the 2nd of the Newton-Cotes closed integration formulas. It
corresponds to the case where the polynomial fn(x) is an 2nd-order polynomial. A
second−order Lagrange polynomial is as follows which indicates that at least three point
is required to fully define the equation.
( x  x1 )  ( x  x2 ) ( x  x0 )  ( x  x2 ) ( x  x0 )  ( x  x1 )
f 2 ( x)  f ( x0 )  f ( x1 )  f ( x2 )
( x0  x1 )( x0  x2 ) ( x1  x0 )( x1  x2 ) ( x2  x0 )( x2  x1 )

Fig: Graphical depiction of Simpson’s 1/3 rule: It consists of taking


the area under a parabola connecting three points.
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 15
The Simpson’s 1/3 Rule
b b
I   f ( x)dx   f 2 ( x)dx
a a

If a and b are designated as x0 and x2 and Substituting the expression of f 2 ( x),


the above integral becomes
 ( x  x1 )  ( x  x2 ) ( x  x0 )  ( x  x2 ) ( x  x0 )  ( x  x1 ) 
x2

I   f ( x0 )  f ( x1 )  f ( x2 ) dx
x0  ( x0  x 1 )( x0  x2 ) ( x1  x0 )( x1  x2 ) ( x2  x 0 )( x2  x1 ) 
After integration and algebraic manipulation, the following formula results
h
I   f ( x0 )  4 f ( x1 )  f ( x2 ) [This Equation is known as Simpson's 1 / 3 Rule]
3
b - a x2  x0
where, h =   step size [as minimum 2 segments are required]
n 2
It can also be written as follows

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 16
Simple Example of Simpson’s 1/3 Rule
Find the integral of the following function from x = 0 to 0.8 using a single
application Simpson’s 1/3 rule. Also find the absolute and relative errors.
f ( x)  0.2  25 x  200 x 2  675 x 3  900 x 4  400 x 5
Solution
b  a 0.8  0
h=   0.4
2 2
The function values
f (a )  f ( x0 )  f (0)  0.2  25(0)  200(0) 2  675(0)3  900(0) 4  400(0) 5  0.2
f (b)  f ( x2 )  f (0.8)  0.2  25(0.8)  200(0.8) 2  675(0.8)3  900(0.8) 4  400(0.8)5
 0.232
x1  x0  h  0  0.4  0.4
f ( x1 )  f (0.4)  2.456
Now using Simpson's 1/3 rule we get,
ba
I approx.   f ( x0 )  4 f ( x1 )  f ( x2 )
6
0.8  0
 (0.232  4  2.456  0.2)  1.3675
6
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 17
Simple Example of Simpson’s 1/3 Rule
Using Analytical approach we get,
b 0.8
I actual   f ( x)dx   (0.2  25 x  200 x 2
 675 x 3
 900 x 4
 400 x 5
)dx
a 0
0.8
 25 x 2 200 x 3 675 x 4 900 x 5 400 x 6 
 0.2 x      
 2 3 4 5 6 0
 25(0.8) 2 200(0.8)3 675(0.8) 4 900(0.8)5 400(0.8)6 
 0.2(0.8)       0
 2 3 4 5 6 
 1.640533
so, Absolute Error, Ea  I actual  I approx.
 1.640533  1.3675  0.2731
I actual  I approx.
and Relative Rrror, E r   100%
I actual
0.2731
  100%  16.6%
1.640533

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 18
Graphical representation of Multiple-Application Simpson’s 1/3 Rule

Fig: Graphical representation of the multiple application of Simpson’s 1/3


rule. Note that the method can be employed only if the number of
segments is even.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 19
General Format of Multiple-Application Simpson’s 1/3 Rule
Just as with the trapezoidal rule, Simpson’s rule can be improved by dividing the
integration interval into a number of segments of equal width

h n 1 n2

I   f ( x0 )  4  f ( xi )  2  f ( xi )  f ( xn ) 
3 i 1,3,5,... i  2,4,6,... 

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 20
Example-2
Evaluate the Integral of following function from x = 0 to 0.8 (a) using multiple-
application Simpson’s 1/3 rule, with n = 4. (b) analytically; (c) Also Find the absolute
and relative errors.
f ( x)  0.2  25 x  200 x 2  675 x 3  900 x 4  400 x 5

Solution :
Here, n  4, a  x0  0 and b  xn  x4  0.8
b  a 0.8  0
h    0.2
n 4

n xn=xn-1 +h (n=1,2,3,4) f(xn)


0 0 0.2
1 0.2 1.288
2 0.4 2.456
3 0.6 3.464
4 0.8 0.232

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 21
Example-2
Now using Multiple application Simpson's 1/3 Rule with n=4, we get
n f(xn)

2
h
I approx.   f ( x)dx   f ( x0 )  4 f ( x1 )  2 f ( x2 )  4 f ( x3 )  f ( x4 )  0 0.2
0 3 1 1.288
0.2
 0.2  4  1.288  2  2.456  4  3.464  0.232 2 2.456
3
 1.6235 3 3.464
Using Analytical approach we get,
b 0.8 4 0.232
I actual   f ( x)dx   (0.2  25 x  200 x
2
 675 x  900 x  400 x )dx
3 4 5

a 0

 1.640533 [According to the previous Example]


so, Absolute Error, Ea  I actual  I approx.
 1.640533  1.6235  0.017067
I actual  I approx.
and Relative Rrror, E r   100%
I actual
0.017067
  100%  1.04%
1.640533
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 22
The Simpson’s 3/8 Rule
The Simpson’s 3/8 rule is the 3rd of the Newton-Cotes closed integration formulas. It
corresponds to the case where the polynomial fn(x) is an 3rd-order polynomial. An
3rd−order Lagrange polynomial is as follows which indicates that at least four point is
required to fully define the equation.

Fig: Graphical depiction of


Simpson’s 3/8 rule: It consists of
taking the area under a parabola
connecting four points.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 23
The Simpson’s 3/8 Rule

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 24
Simple Example of Simpson’s 3/8 Rule
The vertical distance in meters covered by a rocket from t =8 to t = 30 seconds is
given by

Use Simpson 3/8 rule to find the approximate value of the integral.

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 25
Simple Example of Simpson’s 3/8 Rule

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 26
Simple Example of Simpson’s 3/8 Rule

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 27
General Format of Multiple-Application Simpson’s 3/8 Rule

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 28
Example
The vertical distance in meters covered by a rocket from t =8 to t = 30 seconds is
given by

Use Simpson 3/8 multiple segments rule with six segments to estimate the vertical
distance.
30  8
Solution : h   3.6666
6
n tn=tn-1 +h (n=1,2,3,4,5,6) f(tn)
0 8 177.2667
1 11.6666 270.4104
2 15.3333 372.4629
3 19 484.7455
4 22.6666 608.8976
5 26.3333 746.9870
6 30 901.6740
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 29
Example
3h  n -2  4 n -1 5 n -3  3

I   f (t0 )  3  f (ti )  3  f (ti )  2  f (ti )  f (t6 ) 
8  i 1,4,.. i  2,5,.. i  3,6,.. 
3h
  f (t0 )  3  f (t1 )  f (t4 )   3  f (t2 )  f (t5 )   2  f (t3 )   f (t6 ) 
8
3 177.2667  3  270.4104  608.8976  
 (3.6666)  
8  3  372.4629  746.9870   2  484.7455   901.6740 
 11601.4696 m
n f(tn)
0 177.2667
1 270.4104
2 372.4629
3 484.7455
4 608.8976
5 746.9870
6 901.6740

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 30
Example
The vertical distance in meters covered by a rocket from t =8 to t = 30 seconds is
given by

Use Simpson’s 3/8 multiple application rule in conjunction with Simpson's 1/3 rule
with seven segments to estimate the vertical distance. Also perform Error Analysis.
Solution :
30  8 n tn=tn-1 +h (n=1,2,3,4,5,6,7) f(tn)
h  3.1429
7 0 8 177.2667
Here, we will devide 1 11.1429 256.5863
the total segments into 2 14.2857 342.3241
two groups, n1 (=4) and
3 17.4286 435.2749
n 2 =(3), so that we can
4 20.5714 536.3909
apply simpson's 1/3 rule
5 23.7143 646.8260
in the1st group and simpson's
6 26.8571 767.9978
3/8 rule the in 2nd group
7 30 901.6740
ME 261: Numerical Analysis Md. Masudur Rahman
Lecture-3: Numerical Integration 31
Example
Using Simpson 1/3 rule for the first n1=4 segments we get,

Using Simpson 3/8 rule for the last n2= 3 segments we get,

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 32
Example
1.  (uv)dx
 du 
 u  vdx      vdx dx
 dx 
2.
d
dx
 ( f (t )) n 
   
30
140000
Now, I actual   2000  ln    9.8t dt
d
 n( f (t )) n 1   f (t )  
dt
8   140000  2100t   dx dx
  
30 30
d 1
3.  ln( x)  
140000
 2000   ln   dt  9.8   tdt
8   140000  2100t   8 dx x
  140000  
30

 ln     dt  

30
  140000 2100t  8  t2 
 2000    9.8   2 
   140000  2100t   140000  (1)  (2100)   dt dt   8
30

 8  140000

  (140 000  2100t ) 2  
  

  140000 
30 30
 2100t    302  82 
 2000  t  ln      dt   9.8   
   140000  2100t   8 8  140000  2100t    2 

ME 261: Numerical Analysis Md. Masudur Rahman


Lecture-3: Numerical Integration 33
Example
  140000  
 30  ln    30 
 140000  2100  30  140000  2100t  140000 
I actual  2000   
  dt   4096.4
  140000   8 140000  2100t  
 8  ln    
  140000  2100  8   
 30
 140000  
 2000 16.9124   1   dt   4096.4
  140000  2100t  
8
f ( x)
  140000
30
 2000 16.9124   1  
(2100)  
4.  f ( x) dx
 dt   4096.4
 8  2100 140000  2100t  
 ln( f ( x))  c
  140000  
30

 2000 16.9124  t   ln 140000  2100t     4096.4


  2100  8 
  30  66.6667  ln 140000  2100  30   
16.9124   
 2000   8  66.6667  ln 140000  2100  8     4096.4
 
 
 
 2000  16.9124  9.333575  4096.4 11061.2
so, Absolute Error, Ea  I actual  I approx.  11061.2  11061  0.2
I actual  I approx. 0.2
and Relative Rrror, E r   100%   100%  .00181%
I actual 11061.2
ME 261: Numerical Analysis Md. Masudur Rahman

You might also like