Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Introduction to Numerical Integration

1
Integration

Indefinite Integrals Definite Integrals


2 1 2 1
x x 1
 x dx = 2 + c 0 xdx = 2 =
2
0

Indefinite Integrals of a Definite Integrals are


function are functions numbers.
that differ from each
other by a constant.

2
Fundamental Theorem of Calculus

If f is continuous on an interval [a,b],


F is antiderivative of f (i.e., F ' (x) = f(x) )
b
 a
f(x)dx = F(b) − F(a)

x2
There is no antiderivative for : e
b
No closed form solution for :  e dx x2
a

3
The Area Under the Curve
One interpretation of the definite integral is:
Integral = area under the curve

f(x)

b
Area =  f(x)dx
a

a b

4
❑ The function to be integrated may only be known at a
finite set of discrete points (Tabulated). In such cases, an
approximating polynomial is fitted to these discrete points,
or several subsets of the points. The resulting polynomial,
or polynomials, are then integrated. The degree of the
approximating polynomial chosen to represent the
discrete data is the only parameter under our control.
❑ When a known function is to be integrated, several
parameters are under our control. The total number of
discrete points can be chosen arbitrarily. The degree of the
approximating polynomial chosen to represent the
discrete data can be chosen. The locations of the points at
which the known function is discretized can also be chosen
to enhance the accuracy of the procedure
5
Newton-Cotes Methods

In Newton-Cote Methods, the function is approximated by a


polynomial of order n.
Computing the integral of a polynomial is easy.

a
b
f ( x)dx  
a
b
(a
0 + a1 x + ... + a n x)n
dx
b (b 2 − a 2 ) (b n +1 − a n +1 )
a
f ( x)dx a0 (b − a) + a1
2
+ ... + an
n +1

6
Newton-Cotes Methods
◦ Trapezoid Method (First Order Polynomials are used)

(a0 + a1x )dx


b b
a f ( x)dx  
a

◦ Simpson 1/3 Rule (Second Order Polynomials are used)

a
b
f ( x)dx  
b
a
(a0 + a1 x + a 2 x )
2
dx

7
Trapezoid Method

f (b) − f (a)
f (a) + ( x − a)
b−a
f(x)

a b

8
Trapezoid Method
Derivation-One Interval
b 
b f (b) − f (a ) 
I =  f ( x)dx    f (a ) + ( x − a ) dx
a a
 b−a 
b f (b) − f (a ) f (b) − f (a ) 
I    f (a) − a + x dx
a
 b−a b−a 
b 2 b
 f (b) − f (a )  f (b) − f (a ) x
=  f (a) − a x +
 b−a  a b−a 2 a

 f (b) − f (a )  f (b) − f (a ) 2
=  f (a) − a  (b − a ) + (b − a 2 )
 b−a  2(b − a )
f (b) + f (a )
= (b − a )
2
9
Trapezoid Method
f(x)

f (b)

f (a )
b−a
Area = ( f (a) + f (b))
2
a b
10
Trapezoid Method
Multiple Application Rule
f ( x2 ) + f ( x1 )
Area = (x2 − x1 )
f(x) 2
The interval [a, b] is
partitioned into n segments
a = x0  x1  x2  ...  xn = b
b

a
f ( x)dx = sum of the areas
of the trapezoids
x
x0 x1 x2 x3
a b

11
Trapezoid Method
General Formula and Special Case
If the interval is divided into n segments (not necessarily equal)
a = x0  x1  x2  ...  xn = b
n −1


1
(xi +1 − xi )( f ( xi +1 ) + f ( xi ) )
b
 a
f ( x)dx 
i =0 2

Special Case ( Equaliy spaced base points)


xi +1 − xi = h for all i
1 n −1

f ( x)dx  h   f ( x0 ) + f ( xn ) +  f ( xi ) 
b
 a
2 i =1 
12
Example
Given a tabulated Time (s) 0.0 1.0 2.0 3.0
values of the velocity of
an object. Velocity (m/s) 0.0 10 12 14

Obtain an estimate of
the distance traveled in
the interval [0,3].

Distance = integral of the velocity


3
Distance =  0
V (t ) dt

13
Example 1
The interval is divided Time (s) 0.0 1.0 2.0 3.0

into 3 subintervals Velocity 0.0 10 12 14

Base points are0,1,2,3


(m/s)

Trapezoid Method
h = xi +1 − xi = 1
 n −1 
T = h  f ( xi ) + ( f ( x0 ) + f ( xn ) )
1
 i =1 2 
 1 
Distance = 1(10 + 12) + (0 + 14) = 29
 2 

14
Error in estimating the integral
Theorem

Assumption : f ' ' ( x) is continuous on [a,b]


Equal intervals (width = h)
Theorem : If Trapezoid Method is used to
b
approximate  a
f ( x)dx then
b − a 2 ''
Error = − h f ( ) where   [a,b]
12
b−a 2
Error  h max f ' ' ( x)
12 x[ a ,b ]

15
Example 


1
sin( x )dx, find h so that error   10−5
2
0
b−a 2
Error  h max f ' ' ( x )
12 x[ a ,b]
b =  ; a = 0; f ' ( x ) = cos( x ); f ' ' ( x ) = − sin( x )
 2 1
f ' ' ( x )  1  Error  h   10−5
12 2
2 6
 h   10−5  h  0.00437

(b − a ) 
 n = = 719 intervals
h 0.00437

16
Example
x 1.0 1.5 2.0 2.5 3.0

f(x) 2.1 3.2 3.4 2.8 2.7


3
Use Trapezoid method to compute :  1
f ( x)dx

n −1
Trapezoid T ( f , P ) =  ( xi +1 − xi )( f ( xi +1 ) + f ( xi ) )
1
i =0 2

Special Case : h = xi +1 − xi for all i,


 n −1 
T ( f , P ) = h  f ( xi ) + ( f ( x0 ) + f ( xn ) )
1
 i =1 2 

17
Example
x 1.0 1.5 2.0 2.5 3.0
f(x) 2.1 3.2 3.4 2.8 2.7

n−1 
f ( x)dx  h  f ( xi ) + ( f ( x0 ) + f ( xn ) )
3 1
1  i =1 2 
 
= 0.5  3.2 + 3.4 + 2.8 + (2.1 + 2.7 )
1
 2 
= 5.9
18
3/6/2024 19
3/6/2024 20
21
3/6/2024 22
23
24
Motivation for Romberg
Method
Trapezoid formula with a sub-interval h gives an error of the
order O(h2).

We can combine two Trapezoid estimates with intervals h


and h/2 to get a better estimate.

25
Romberg Method
Estimates using Trapezoid method intervals of size h, h/2, h/4, h/8 ...


b
are combined to improve the approximation of f(x) dx
a

First column is obtained R(0,0)


using Trapezoid Method
R(1,0) R(1,1)

R(2,0) R(2,1) R(2,2)

R(3,0) R(3,1) R(3,2) R(3,3)


The other elements
are obtained using
the Romberg Method
26
First Column
Recursive Trapezoid Method
b−a
R (0,0) =  f (a) + f (b)
2

 2 ( n−1) 
R(n,0) = R(n − 1,0) + h   f (a + (2k − 1)h )
1
2  k =1 
b−a
h= n
2
27
Derivation of Romberg Method


b
b−a
f ( x )dx = R( n − 1,0) + O ( h 2 ) Trapezoid method with h = n −1
a
2


b
f ( x )dx = R( n − 1,0) + a2h 2 + a4h 4 + a6h 6 + ... ( eq1)
a
More accurate estimate is obtained by R(n,0)


b
1 1 1
f ( x )dx = R( n,0) + a2h 2 + a4h 4 + a6h 6 + ... ( eq2)
4 16 64
a
eq1 − 4 * eq2 gives


b
f ( x )dx =
1
4  R(n,0) − R(n − 1,0) + b4h 4 + b6h6 + ...
3
a
28
Romberg Method
R(0,0)
b−a
R (0,0) =  f ( a ) + f (b) R(1,0) R(1,1)
2 R(2,0) R(2,1) R(2,2)
b−a
h= n
, R(3,0) R(3,1) R(3,2) R(3,3)
2
2( n −1) 
1 
R( n,0) = R( n − 1,0) + h 
2  
 k =1

f (a + ( 2k − 1)h )

R ( n, m ) = m
1
4 −1
 
4m  R( n, m − 1) − R( n − 1, m − 1) n  1, m  1

29
Property of Romberg Method
Theorem R(0,0)
b R(1,0) R(1,1)


a
f ( x)dx = R(n, m) + O(h 2 m + 2 ) R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)

Error Level O(h 2 ) O(h 4 ) O(h 6 ) O(h8 )

30
Example

1
Compute x 2dx 0.5

0 3/8 1/3

b−a
h = 1, R(0,0) =  f (a ) + f (b) = 1 0 + 1 = 0.5
2 2
1 1 11 11 3
h = , R(1,0) = R(0,0) + h( f ( a + h )) =   +   =
2 2 22 24 8

R ( n, m ) = m
1
4 −1
 
4m  R( n, m − 1) − R( n − 1, m − 1) for n  1, m  1

1  3 1 1
R(1,1) = 1 4  R(1,0) − R(0,0) = 4  −  =
1
4 −1 3  8 2 3

31
0.5

Example (cont.) 3/8 1/3

11/32 1/3 1/3

1 1 1  3 1  1 9  11
h= , R ( 2,0) = R (1,0) + h( f ( a + h ) + f ( a + 3h )) =   +  +  =
4 2 2  8  4  16 16  32

R ( n, m ) = m
1
4 −1
 
4m  R( n, m − 1) − R( n − 1, m − 1)

1  11 3  1
R( 2,1) = 4  R( 2,0) − R(1,0) = 4  −  =
1
3 3  32 8  3

R( 2,2) = 2
1
4 −1
 1 16 1  1
42  R ( 2,1) − R(1,1) =  −  =
15  3 3  3

32
When do we stop?
STOP if
R( n, n ) − R( n, n − 1)  
or
After a given number of steps,
for example, STOP at R(4,4)

33
Gauss Quadrature

34
Motivation
Trapezoid Method :
 n −1 

 
b
 
f ( xi ) + ( f ( x0 ) + f ( xn ) )
1
f ( x )dx  h 
2
a  i =1 
It can be expressed as :


n


b
f ( x )dx  ci f ( xi )
a
i =0
 h i = 1,2,..., n − 1
where ci = 
 0.5 h i = 0 and n
35
General Integration Formula


n


b
f ( x )dx  ci f ( xi )
a
i =0
ci : Weights xi : Nodes
Problem :
How do we select ci and xi so that the formula
gives a good approximation of the integral?

36
Lagrange Interpolation
b b
a
f ( x)dx   Pn ( x)dx
a

where Pn ( x) is a polynomial that interpolates f(x)


at the nodes : x0 , x1 ,..., xn
 n 
   i ( x) f ( xi ) dx
b b b
a
f ( x)dx   Pn ( x)dx = 
a a
 i =0 
n
  f ( x)dx   ci f ( xi )
b b
where ci =   i ( x) dx
a a
i =0

37
Example
Determine the Gauss Quadrature Formula of 2

If the nodes are given as (-1, 0 , 1)



−2
f ( x )dx

Solution: First, we need to find l0(x), l1(x), l2(x)

2 2 2
Then compute:


c0 = l0 ( x )dx,

−2
c1 =

−2
l1( x )dx, c2 =

−2
l2 ( x )dx

38
Solution
( x − x1)( x − x 2) x ( x − 1)
l0 ( x ) = =
( x 0 − x1)( x 0 − x 2) 2
( x − x 0)( x − x 2)
l1( x ) = = −( x + 1)( x − 1)
( x1 − x 0)( x1 − x 2)
( x − x 0)( x − x1) x ( x + 1)
l2 ( x ) = =
( x 2 − x 0)( x 2 − x1) 2
2 2 2

  
x ( x − 1) 8 4 x ( x + 1) 8
c0 = dx = , c1 = − ( x + 1)( x − 1)dx = − , c2 = dx =
2 3 3 2 3
−2 −2 −2
2


8 4 8
The Gauss Quadrature Formula for f ( x )dx = f ( −1) − f (0) + f (1)
3 3 3
-2
39
Using the Gauss Quadrature Formula
Case 1 : Let f ( x ) = x 2
2 2

  2 16
The exact value for f ( x )dx = x dx =
3
-2 -2
8 4 8
The Gauss Quadrature Formula = f ( −1) − f (0) + f (1)
3 3 3
8 2 4 2 8 2 16
= ( −1) − (0) + (1) = , which is the same exact answer
3 3 3 3

40
Using the Gauss Quadrature Formula
Case 2 : Let f ( x ) = x 3
2 2

The exact value for



-2
f ( x )dx =

-2
x 3dx = 0

8 4 8
The Gauss Quadrature Formula = f ( −1) − f (0) + f (1)
3 3 3
8 3 4 3 8 3
= ( −1) − (0) + (1) = 0, which is the same exact answer
3 3 3

41
Recursive Trapezoid Method
Estimate based on one interval :
f(x)

h =b−a
b−a
R (0,0) = ( f ( a ) + f ( b) )
2

a a+h

42
Recursive Trapezoid Method
Estimate based on 2 intervals :
f(x)

b−a
h=
2
b−a  
R (1,0) = f ( a + h ) +
1
( f ( a ) + f ( b ) )
2  2 

R(0,0) + h f ( a + h )
1
R(1,0) =
2

Based on previous estimate a a+h a + 2h


Based on new point

43
Recursive Trapezoid Method
f(x)
b−a
h=
4
b−a
R (2,0) =  f (a + h) + f (a + 2h) + f (a + 3h)
4

+ ( f (a ) + f (b) )
1
2 

R (1,0) + h f (a + h) + f (a + 3h)
1
R (2,0) =
2

a a + 2h a + 4h
Based on previous estimate
Based on new points

44
Recursive Trapezoid Method
Formulas
b−a
R (0,0) =  f (a) + f (b)
2

 2 ( n−1) 
R(n,0) = R(n − 1,0) + h   f (a + (2k − 1)h )
1
2  k =1 
b−a
h= n
2
45
Recursive Trapezoid Method
b−a
h = b − a, R (0,0) =  f (a) + f (b)
2
b−a 1 
R(1,0) = R(0,0) + h  f (a + (2k − 1)h )
1
h= ,
2 2  k =1 
b−a  2 
R(2,0) = R(1,0) + h  f (a + (2k − 1)h )
1
h= 2 ,
2 2  k =1 
b−a 2 
2

R(3,0) = R(2,0) + h  f (a + (2k − 1)h )


1
h= 3 ,
2 2  k =1 
..................
2 
( n−1)
b−a
R(n,0) = R(n − 1,0) + h   f (a + (2k − 1)h )
1
h= n
,
2 2  k =1 
46
Example on Recursive
Trapezoid
Use Recursive Trapezoid method to estimate :
 /2

 0
sin( x )dx by computing R(3,0) then estimate the error

n h R(n,0)
0 (b-a)=/2 (/4)[sin(0) + sin(/2)]=0.785398
1 (b-a)/2=/4 R(0,0)/2 + (/4) sin(/4) = 0.948059
2 (b-a)/4=/8 R(1,0)/2 + (/8)[sin(/8)+sin(3/8)] = 0.987116
3 (b-a)/8=/16 R(2,0)/2 + (/16)[sin(/16)+sin(3/16)+sin(5/16)+ sin(7/16)] =
0.996785

Estimated Error = |R(3,0) – R(2,0)| = 0.009669

47
Advantages of Recursive Trapezoid
Recursive Trapezoid:
Gives the same answer as the standard Trapezoid method.
Makes use of the available information to reduce the computation time.
Useful if the number of iterations is not known in advance.

48
Improper Integrals
Methods discussed earlier cannot be used directly to
approximate improper integrals (one of the limits is  or − )
 Use a transformation like the following
1

 
b
a 1 1
f ( x )dx = f  dt, (assuming ab  0)
a
1 t 2 t
b
and apply the method on the new function.
 
  

 
1
1 1 1 
Example : 2
dx = 2 2
dt
x t  1 
t 
1 0
  
49

You might also like