You are on page 1of 51

Numerical Integration

1
Differentiation
y f  xi  x   f  xi 

x x

 Dictionary definition of differentiate -


“to mark off by differences, distinguish;
..to perceive the difference in or
between”
 Mathematical definition of derivative -
rate of change of a dependent variable
with respect to an independent variable
f(x)

f  xi  x

y
f  xi 

x x

y f  xi  x  f  xi 

x x
Integration
 The inverse process of differentiation
 Dictionary definition of integrate - “to
bring together, as parts, into a whole;
to unite; to indicate the total amount”
 Mathematically, it is the total value or
summation of f(x)dx over a range of x.
In fact the integration symbol is
actually a stylized capital S intended to
signify the connection between
integration and summation.
Introduction to Numerical
Integration
 Definitions
 Upper and Lower Sums
 Trapezoid Method (Newton-Cotes Methods)
 Romberg Method
 Gauss Quadrature
 Examples

5
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.

6
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
7
The Area Under the Curve
One interpretation of the definite integral is:
Integral = area under the curve

b
Area   f(x)dx
a

8
Upper and Lower Sums
The interval is divided into subintervals.
Partition P  a  x0  x1  x2  ...  xn  b

Define
mi  min  f ( x) : xi  x  xi 1 f(x)
M i  max  f ( x) : xi  x  xi 1

n 1
Lower sum L( f , P )   mi  xi 1  xi 
i 0
n 1
Upper sum U ( f , P)   M i  xi 1  xi 
i 0 x0 x1 x2 x3
a b
9
Upper and Lower Sums

n 1
Lower sum L( f , P)   mi  xi 1  xi 
i 0
n 1
Upper sum U ( f , P)   M i  xi 1  xi  f(x)
i 0

L U
Estimate of the integral 
2
U L
Error 
2
x0 x1 x2 x3
a b
10
Example
1
 0
x 2 dx

 1 2 3 
Partition : P  0, , , ,1
 4 4 4 
n  4 (four equal intervals)
1 1 9
m0  0, m1  , m2  , m3 
16 4 16
1 1 9
M 0  , M1  , M 2  , M 3  1
16 4 16

1 1 1 3
xi 1  xi  for i  0,1, 2, 3 0 1
4 4 2 4

11
Example
n 1
Lower sum L( f , P )   mi  xi 1  xi 
i 0

1 1 1 9  14
L( f , P)   0    
4  16 4 16  64
n 1
Upper sum U ( f , P )   M i  xi 1  xi 
i 0

11 1 9  30
U ( f , P)      1 
4 16 4 16  64
1  30 14  11
Estimate of the integral     
2  64 64  32
1  30 14  1
Error     
2  64 64  8 1 1 3
0 1
4 2 4
12
Upper and Lower Sums
• Estimates based on Upper and Lower
Sums are easy to obtain for monotonic
functions (always increasing or always
decreasing).
• For non-monotonic functions, finding
maximum and minimum of the function
can be difficult and other methods can be
more attractive.

13
Newton-Cotes Methods
 In Newton-Cotes 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

14
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 
 a1x  a2 x dx
2

15
Trapezoid Method
 Derivation-One Interval
 Multiple Application Rule
 Estimating the Error
 Recursive Trapezoid Method

16
Trapezoidal Rule

 First of the Newton-Cotes closed


integration formulas
 Corresponds to the case where the
polynomial is a first order

b b

I   f  x dx   f 1  x dx
a a

f n  x   a0  a1 x
b b

I   f  x dx   f 1  x dx
a a

f n  x   a0  a1 x

A straight line can be represented as:

f  b  f  a 
f1  x  f  a   x  a
ba
b b

I   f  x dx   f 1  x dx
a a
b
f b  f  a 
 f a    x  a dx
a
ba

Integrate this equation. Results in the trapezoidal rule.

f  a   f  b
I  b  a 
2
f  a   f  b
I  b  a 
2
The concept is the same but the trapezoid is on its
side.
base

height
height

height
width

base
Trapezoid Method
b
I   f ( x)dx
f (b)  f (a) a
f (a)  ( x  a)
ba b  f (b)  f (a ) 
I    f (a)  ( x  a ) dx
a
 ba 
b
 f (b)  f (a ) 
  f (a)  a x
 ba  a
2 b
f (b)  f (a ) x

ba 2 a

f (b)  f (a )
 b  a 
2
21
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
22
Trapezoid Method
f(x)

f (b)

f (a)
ba
Area   f (a)  f (b)
2
a b
23
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
24
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
f ( x)dx   xi 1  xi  f ( xi 1 )  f ( xi ) 
b 1
 a
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 
25
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
26
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 
27
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 ]

28
Estimating the Error
For Trapezoid Method

How many equally spaced intervals are



needed to compute  0
sin( x)dx
to 5 decimal digit accuracy ?

29
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 )
1
f ' ' ( x )  1  Error  h   105
2
12 2
6
 h   105  h  0.00437
2

(b  a ) 
 n   719 intervals
h 0.00437 30
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 
31
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
32
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

33
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
34
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
35
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
36
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 
37
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

38
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.

39
Simpson’s 1/3 Rule

 Corresponds to the case where the


function is a second order polynomial

b b

I   f  x dx   f 2  x dx
a a

f n  x   a0  a1 x  a2 x 2
Simpson’s 1/3 Rule

 Designate a and b as x0 and x2, and


estimate f2(x) as a second order
Lagrange polynomial
b b

I   f  x dx   f 2  x dx
a a

  x  x1  x  x2  
x2

  f  x0 .......dx
x 0  0
x  x1  x0  x2  
Simpson’s 1/3 Rule

 After integration and algebraic


manipulation, we get the following
equations

h
I   f  x0   4 f  x1   f  x2 
3
f  x0   4 f  x1   f  x2 
 b  a 
6
}

width average height


Error
Single application of Trapezoidal Rule.
1
Et   f ' '  b  a 
3

12
where a    b

Single application of Simpson’s 1/3 Rule


1
Et   f (4)
 b  a  5

2880
Multiple Application of Simpson’s
1/3 Rule

x1 x2 xn

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


x0 x1 xn 1
n 1 n2
f  x0   4  f x   2  f x   f x 
i j n

I  b  a  i 1, 3,5.. j  2 , 4 , 6..

3n

Ea  
b  a 4
f
5

4
180n
n 1 n2
f  x0   4  f x   2  f x   f x 
i j n

I  b  a  i 1, 3,5.. j  2 , 4 , 6..

3n

The odd points


represent the middle
term for each
application. Hence
carry the weight 4
The even points are
common to adjacent
applications and are
counted twice.
Simpson’s 3/8 Rule

 Corresponds to the case where the


function is a third order polynomial

b b
I   f  x dx   f 3  x dx
a a

f n  x   a0  a1 x  a2 x 2  a3 x 3

I   f  x0   3 f  x1   3 f  x2   f  x3 
3h
8
Integration of Unequal Segments
 Experimental and field study data is
often unevenly spaced
 In previous equations we grouped the
term (i.e. hi) which represented
segment width.
n 1
f  x0   2 f  xi   f  xn 
I  b  a  i 1

2n
f  x0   f  x1  f  x1   f  x2  f  xn  1   f  xn 
I h h  h
2 2 2
Integration of Unequal Segments
 We should also consider alternately
using higher order equations if we can
find data in consecutively even
segments
trapezoidal
1/3 rule
trapezoidal rule
rule
3/8
rule
EXAMPLE
Integrate the following using the trapezoidal rule,
Simpson’s 1/3 Rule and a multiple application of
the trapezoidal rule with n=2. Compare results with
the analytical solution.

 dx
2x
xe
0
Simpson’s 1/3 Rule
f(2) = 109.196

h
I   f  x0   4 f  x1   f  x2 
3
f  x0   4 f  x1   f  x2 
 b  a 
6
0  4109.196  11923.83
 4  0  8240.41
6
5216.93  8240.41
t   100  57.96%
5216.93
Multiple Application of
the Trapezoidal Rule

n 1
f  x0   2 f  xi   f  xn 
I  b  a  i 1
2n
0  2109.196  11923.83
 4  0  12142.22
22
We are obviously not doing
5216.93  12142.22
t   100  133% very well on our estimates.
5216.93 Lets consider a scheme
where we “weight” the
....end of example
estimates

You might also like