Integration Lecture

Report
Numerical Integration

Basic Numerical Integration





We want to find integration of functions of various
forms of the equation known as the Newton Cotes
integration formulas.
Trapezoidal Rule
Simpson’s Rule
 1/3 Rule
 3/8 Rule
Midpoint
Gaussian Quadrature
USC
Basic Numerical Integration
• Weighted sum of function values

b
a
n
f ( x )dx   c i f ( x i )
i 0
f(x)
x0
 c0 f ( x 0 )  c 1 f ( x 1 )    c n f ( x n )
x1
xn-1
xn
USC
x
Numerical Integration
Idea is to do integral in small parts, like the way you first learned
integration - a summation
Numerical methods just try to make it faster and more accurate
12
10
8
6
4
2
0
3
5
7
9
11
13
15
USC
Numerical Integration

Newton-Cotes Closed Formulae -- Use
both end points

Trapezoidal Rule : Linear
Simpson’s 1/3-Rule : Quadratic
Simpson’s 3/8-Rule : Cubic

Boole’s Rule : Fourth-order



Newton-Cotes Open Formulae -- Use only
interior points

midpoint rule
USC
Trapezoid Rule

Straight-line approximation

b
a
1
f ( x )dx   c i f ( x i )  c 0 f ( x 0 )  c 1 f ( x 1 )
i 0
h
  f ( x 0 )  f ( x 1 )
2
f(x)
L(x)
x0
x1
x
USC
Trapezoid Rule

Lagrange interpolation
x  x0
x  x1
L( x) 
f ( x0 ) 
f ( x1 )
x0  x1
x1  x0
xa
dx
let a  x 0 , b  x1 ,  
, d  ; h  b  a
ba
h
 x  a    0

  L( )  (1   ) f (a )  ( ) f (b)
x  b    1 
USC
Trapezoid Rule


b
a
Integrate to obtain the rule
b
1
a
0
f ( x)dx   L( x)dx  h  L( )d
1
1
0
0
 f (a)h  (1   )d  f (b)h   d
 f (a)h ( 

2
2
1
)  f (b)h
0

2 1
2
0
h
  f (a )  f (b) 
2
USC
Example:Trapezoid Rule

Evaluate the integral
 Exact solution

4
0
4
0
xe 2 x dx
4
 x 2x 1 2x 
xe dx   e  e 
4
2
0
2x
1
1 2x
 e ( 2 x  1 )  5216.926477
4
0

Trapezoidal Rule
I
4
0
40
 f ( 0 )  f ( 4 )  2( 0  4e 8 )  23847.66
xe dx 
2
5216.926  23847.66

 357.12%
5216.926
2x
USC
Simpson’s 1/3-Rule
Approximate the function by a parabola

b
a
2
f ( x )dx   c i f ( x i )  c 0 f ( x 0 )  c 1 f ( x 1 )  c 2 f ( x 2 )
i 0
h
  f ( x 0 )  4 f ( x 1 )  f ( x 2 )
3
f(x)
x0
h
L(x)
x1
h
x2
x
USC
Simpson’s 1/3-Rule
( x  x 0 )( x  x 2 )
( x  x 1 )( x  x 2 )
L( x ) 
f ( x0 ) 
f ( x1 )
( x 0  x 1 )( x 0  x 2 )
( x 1  x 0 )( x 1  x 2 )
( x  x 0 )( x  x 1 )

f ( x2 )
( x 2  x 0 )( x 2  x 1 )
ab
2
x  x1
ba
dx
h
, 
, d 
2
h
h
 x  x 0    1

 x  x1    0
x  x    1
2

let
x0  a , x 2  b , x1 
L(  ) 
 (  1 )
2
f ( x0 )  ( 1   ) f ( x1 ) 
2
 (  1 )
2
f ( x2 )
USC
Simpson’s 1/3-Rule

b
a
Integrate the Lagrange interpolation
1
h 1
f(x)dx  h L(  )dξ  f(x 0 )  ξ(ξ  1 )dξ
1
2 1
1
h 1
2
 f(x 1 )h ( 1  ξ )dξ  f(x 2 )  ξ(ξ  1 )dξ
0
2 1
1
1
3
2
3
h ξ
ξ
ξ
 f(x 0 ) (

)  f(x 1 )h(ξ 
)
2 3
2 1
3 1
1
h ξ
ξ
 f(x 2 ) (

)
2 3
2 1
3

b
a
2
h
f(x)dx   f(x 0 )  4f(x 1 )  f(x 2 )
3
USC
Simpson’s 3/8-Rule
Approximate by a cubic polynomial

b
a
3
f ( x )dx   c i f ( x i )  c0 f(x0 )  c 1 f(x 1 )  c 2 f(x 2 )  c 3 f(x 3 )
i 0
3h
 f ( x0 )  3 f ( x1 )  3 f ( x 2 )  f ( x 3 )

8
L(x)
x0
h
f(x)
x1
h
x2
h
x3
x
USC
Simpson’s 3/8-Rule
( x  x 1 )( x  x 2 )( x  x 3 )
L( x ) 
f ( x0 )
( x 0  x 1 )( x 0  x 2 )( x 0  x 3 )
( x  x 0 )( x  x 2 )( x  x 3 )

f ( x1 )
( x 1  x 0 )( x 1  x 2 )( x 1  x 3 )

b
a

( x  x 0 )( x  x 1 )( x  x 3 )
f ( x2 )
( x 2  x 0 )( x 2  x 1 )( x 2  x 3 )

( x  x 0 )( x  x 1 )( x  x 2 )
f ( x3 )
( x 3  x 0 )( x 3  x 1 )( x 3  x 2 )
f(x)dx  
b
a
b-a
L(x)dx ; h 
3
3h
 f ( x 0 )  3 f ( x 1 )  3 f ( x 2 )  f ( x 3 )

8
USC
Example: Simpson’s Rules
Evaluate the integral

Simpson’s 1/3-Rule
4
I   xe2 x dx 
0

4
0
xe 2 x dx
h
 f (0)  4 f (2)  f (4)
3
2
0  4(2e4 )  4e8   8240.411
3
5216.926  8240.411

 57.96%
5216.926


Simpson’s 3/8-Rule
4
I   xe 2 x dx 
0
3h 
4
8

f
(0)

3
f
(
)

3
f
(
)

f
(4)

8 
3
3
3(4/3)
0  3(19.18922)  3(552.33933)  11923.832  6819.209
8
5216.926  6819.209

 30.71%
5216.926

USC
Midpoint Rule
Newton-Cotes Open Formula

b
a
f ( x )dx  ( b  a ) f ( x m )
ab
(b  a )
 (b  a )f (
)
f (  )
2
24
3
f(x)
a
xm
x
b
USC
Two-point Newton-Cotes
Open Formula
Approximate by a straight line

b
a
ba
( b  a )3
 f ( x1 )  f ( x 2 ) 
f ( x )dx 
f (  )
2
108
f(x)
x0
h
x1
h
x2
h
x3
x
USC
Three-point Newton-Cotes Open
Formula
Approximate by a parabola

b
a
ba
2 f ( x 1 )  f ( x 2 )  2 f ( x 3 )
f ( x )dx 
3
7 ( b  a )5

f (  )
23040
f(x)
x0
h
x1
h
x2
h
x3
h
x4
USC
x
Better Numerical Integration

Composite integration
Composite Trapezoidal Rule
 Composite Simpson’s Rule

Richardson Extrapolation
 Romberg integration

USC
Apply trapezoid rule to multiple segments over
integration limits
Two segments
Three segments
7
7
6
6
5
5
4
4
3
3
2
2
1
1
0
0
3
5
7
9
11
13
15
3
Four segments
5
7
9
11
13
15
Many segments
7
7
6
6
5
5
4
4
3
3
2
2
1
1
0
0
3
5
7
9
11
13
15
3
5
7
9
11
13
15
USC
Composite Trapezoid Rule

b
a
x1
x2
xn
x0
x1
xn  1
f(x)dx   f(x)dx   f(x)dx    
f(x)dx
h
 f(x0 )  f(x 1 )  h  f(x 1 )  f(x 2 )    h  f(x n1 )  f(x n )
2
2
2
h
  f(x 0 )  2 f(x 1 )    2f(xi )    2 f ( x n1 )  f ( x n )
2
f(x)

ba
h
n
x0
h
x1
h
x2
h
x3
h
x4
USC
x
Composite Trapezoid Rule
Evaluate the integral
4
I   xe 2 x dx
0
h
 f ( 0 )  f ( 4 )  23847.66
  357.12%
2
h
n  2 , h  2  I   f ( 0 )  2 f ( 2 )  f ( 4 )  12142.23   132.75%
2
h
n  4 ,h  1  I   f ( 0 )  2 f ( 1 )  2 f ( 2 )
2
 2 f ( 3 )  f ( 4 )  7288.79
  39.71%
h
n  8 , h  0.5  I   f ( 0 )  2 f ( 0.5 )  2 f ( 1 )
2
 2 f ( 1.5 )  2 f ( 2 )  2 f ( 2.5 )  2 f ( 3 )
 2 f ( 3.5 )  f ( 4 )  5764.76
  10.50%
h
n  16 , h  0.25  I   f ( 0 )  2 f ( 0.25 )  2 f ( 0.5 )  
2
 2 f ( 3.5 )  2 f ( 3.75 )  f ( 4 )
 5355.95
  2.66%
n  1, h  4  I 
USC
Composite Trapezoid
Example
2
1
1 1  x dx
x
1.00
1.25
1.50
1.75
2.00
f(x)
0.5000
0.4444
0.4000
0.3636
0.3333
USC
Composite Trapezoid Rule with
Unequal Segments
4
Evaluate the integral
I   xe 2 x dx
0
 h1 = 2, h2 = 1, h3 = 0.5, h4 = 0.5
2
3
3.5
0
2
3
I   f ( x)dx   f ( x)dx  
4
f ( x)dx   f ( x)dx
3.5
h1
h2
  f (0)  f (2)   f (2)  f (3)
2
2
h3
h4
  f (3)  f (3.5)   f (3.5)  f (4)
2
2
2
1 4
0.5 6
4
6
 0  2e  2e  3e 
3e  3.5e 7
2
2
2
0.5

3.5e 7  4e8  5971.58
   14.45%
2

 





USC
Composite Simpson’s Rule
Piecewise Quadratic approximations
ba
h
n
f(x)
…...
x0 h x1 h x2 h x3 h
x4
xn-2 xn-1
xn
USC
x
Composite Simpson’s Rule
Multiple applications of Simpson’s rule

b
a
x2
x4
xn
x0
x2
xn  2
f(x)dx   f(x)dx   f(x)dx    
f(x)dx
h
h
  f(x 0 )  4 f(x 1 )  f(x 2 )   f(x 2 )  4 f(x 3 )  f(x 4 )
3
3
h
    f(x n 2 )  4f(xn 1 )  f(x n )
3
h
  f(x 0 )  4 f(x 1 )  2f(x2 )  4 f(x 3 )  2f(x4 )  
3
 4 f(x 2i - 1 )  2 f ( x 2 i )  4f(x2i  1 )  
 2 f ( x n 2 )  4 f ( x n 1 )  f ( x n )
USC
Composite Simpson’s Rule
4
I   xe 2 x dx
Evaluate the integral
 n = 2, h = 2
0
h
I   f ( 0 )  4 f ( 2 )  f ( 4 )
3
2
 0  4( 2e 4 )  4 e 8  8240.411    57.96%
3



n = 4, h = 1
h
I   f ( 0 )  4 f ( 1 )  2 f ( 2 )  4 f ( 3 )  f ( 4 )
3
1
 0  4 ( e 2 )  2( 2 e 4 )  4 ( 3e 6 )  4 e 8
3
 5670.975    8.70%


USC
Composite Simpson’s
Example
2
1
1 1  x dx
x
1.00
1.25
1.50
1.75
2.00
f(x)
0.5000
0.4444
0.4000
0.3636
0.3333
USC
Composite Simpson’s Rule with
Unequal Segments
4
I   xe 2 x dx
Evaluate the integral
 h1 = 1.5, h2 = 0.5
3
4
0
3
0
I   f ( x)dx   f ( x)dx
h1
  f (0)  4 f (1.5)  2 f (3)
3
h2
  f (3)  4 f (3.5)  2 f (4)
3
1.5
0.5 6
3
6

0  4(1.5e )  3e 
3e  4(3.5e 7 )  4e8
3
3
 5413.23    3.76%




USC
Richardson Extrapolation
Use trapezoidal rule as an example


b
a
subintervals: n = 2j = 1, 2, 4, 8, 16, ….

h
f(x)dx   f(x0 )  2 f(x 1 )    2 f ( x n1 )  f ( x n )   c j h 2 j
2
j 1
j n Formula
h
0 1
I 0   f ( a )  f ( b )
2
h
1 2
I 1   f ( a )  2 f ( x 1 )  f ( b )
4
h
2 4
I 2   f ( a )  2 f ( x 1 )  2 f ( x 2 )  2 f ( x 3 )  f ( b )
8
h
 f ( a )  2 f ( x 1 )    2 f ( x 7 )  f ( b )
3 8
I3 
16
 

h
j 2 j I j  j  f ( a )  2 f ( x 1 )    2 f ( x n  1 )  f ( b )
2
USC
Richardson Extrapolation
For trapezoidal rule
b
A   f ( x )dx  A( h )  c 1 h 2  
a
 A  A( h )  c 1 h 2  c 2 h 4 

h
h 2
h 4

A

A
(
)

c
(
)

c
(
) 
1
2

2
2
2
1
h
 c2 4
 A   4 A( )  A( h )  h    B( h )  b2 h 4  
3
2
 4

 A  B ( h )  b2 h 4 
1 
h




C
(
h
)

16
B
(
)

B
(
h
)
h
h 4




15
2
A

B
(
)

b
(
)




2


2
2


kth level of extrapolation
4 C ( h/2)  C ( h )
D( h ) 
4k  1
k
USC
Romberg Integration
Accelerated Trapezoid Rule
I j ,k 
4 k I j 1 ,k  I j ,k
4 1
k
; k  1, 2, 3,
Trapezoid
Simpson' s
Boole' s
k 0
O( h 2 )
k1
O( h 4 )
k2
O( h 6 )
k3
O( h 8 )
k4
O ( h 10 )
h
I 0 ,0
I 0 ,1
I 0,2
I 0,3
I 0 ,4
h/ 2
h/ 4
I 1,0
I 2 ,0
I 1, 1
I 2 ,1
I 1, 2
I 2,2
I 1, 3
h/ 8
I 3 ,0
I 3 ,1
h / 16
I 4 ,0
4 I j  1,0  I j ,0
16 I j  1, 1  I j , 1
64 I j  1, 2  I j , 2
256I j  1, 3  I j , 3
3
15
63
255
USC
Romberg Integration
Accelerated Trapezoid Rule
4
I   xe 2 x dx  5216.926477
0
Trapezoid Simpson' s
k 0
k1
h4
h2
h1
h  0.5
h  0.25

O( h 2 )
23847.7
12142.2
7288.79
5764.76
5355.95
 2.66%
O( h 4 )
8240.41
5670.98
5256.75
5219.68
Boole' s
k2
O( h 6 )
5499.68
5229.14
5217.20
k3
k4
O( h 8 )
5224.84
5217.01
O( h 10 )
5216.95
 0.0527%  0.0053%  0.00168%  0.00050%
USC
Romberg Integration
Example
2
1
1 1  x dx
x
1.00
1.25
1.50
1.75
2.00
f(x)
0.5000
0.4444
0.4000
0.3636
0.3333
USC
Gaussian Quadratures

Newton-Cotes Formulae


use evenly-spaced functional values
Gaussian Quadratures
select functional values at non-uniformly
distributed points to achieve higher accuracy
 change of variables so that the interval of
integration is [-1,1]
 Gauss-Legendre formulae

USC
Gaussian Quadrature on [-1, 1]

1
1
n
f ( x )dx   c i f ( x i )  c 1 f ( x 1 )  c 2 f ( x 2 )    c n f ( x n )
i 1
n2:

1
1
f(x)dx
 c 1 f(x 1 )  c 2 f(x 2 )
-1

x1
x2
1
Choose (c1, c2, x1, x2) such that the method
yields “exact integral” for f(x) = x0, x1, x2, x3
USC
Gaussian Quadrature on [-1, 1]

n2:
1
1
f(x)dx  c1 f(x1 )  c 2 f(x 2 )
Exact integral for f = x0, x1, x2, x3

f


f

f

f

Four equations for four unknowns
1
 1   1dx  2  c 1  c 2
1
1
 x   xdx  0  c 1 x 1  c 2 x 2
1
2
 x   x dx   c 1 x 12  c 2 x 22
1
3
1
2
2
1
 x   x 3 dx  0  c 1 x 13  c 2 x 23
3
1
1
I   f ( x )dx  f ( 
1
1
3
c 1  1
c  1
 2
1

  x1 
3

1

 x2  3

) f (
1
3
)
USC
Gaussian Quadrature on [-1, 1]
n3:
-1


1
1
x1
f ( x )dx  c1 f ( x1 )  c 2 f ( x 2 )  c 3 f ( x 3 )
x2
x3
1
Choose (c1, c2, c3, x1, x2, x3) such that
the method yields “exact integral” for
f(x) = x0, x1, x2, x3,x4, x5
USC
Gaussian Quadrature on [-1, 1]
1
f  1   xdx  2  c1  c2  c3
1
1
f  x   xdx  0  c1 x1  c2 x2  c3 x3
1
1
2
f  x   x dx   c1 x12  c2 x22  c3 x32
3
1
2
2
1
f  x 3   x 3 dx  0  c1 x13  c2 x23  c3 x33
1
1
2
f  x   x dx   c1 x14  c2 x24  c3 x34
5
1
4
4
c1  5 / 9
c  8 / 9
 2
c3  5 / 9

 x1   3 / 5
 x2  0

 x3  3 / 5
1
f  x 5   x 5 dx  0  c1 x15  c2 x25  c3 x35
1
USC
Gaussian Quadrature on [-1, 1]
Exact integral for f = x0, x1, x2, x3, x4, x5
I
1
1
5
3
8
5
3
f ( x )dx  f ( 
) f (0 ) f (
)
9
5
9
9
5
USC
Gaussian Quadrature on [a, b]
Coordinate transformation from [a,b] to [-1,1]
ba
ba
t
x
2
2
 x  1  t  a

x  1  t  b
a

b
a
t1
f ( t )dt  
1
1
t2
b
1
ba
ba ba
f(
x
)(
)dx   g( x )dx
1
2
2
2
USC
Example: Gaussian Quadrature
4
Evaluate I  te 2 t dt  5216.926477
0
Coordinate transformation
ba
ba
t
x
 2 x  2 ; dt  2dx
2
2
4
1
I   te dt   ( 4 x  4 )e
2t
0
4 x4
1
1
dx   f ( x )dx
1
Two-point formula
1
I   f ( x )dx  f (
1
1
) f (
1
) (4 
4
4
)e
3
3
3
 9.167657324 3468.376279 3477.543936
4
3
(4 
4
4
)e
4
3
3
(   33.34% )
USC
Example: Gaussian Quadrature
Three-point formula
5
8
5
I   f ( x )dx  f (  0.6 )  f ( 0 )  f ( 0.6 )
1
9
9
9
5
8
5
4  0.6
4
 ( 4  4 0.6 )e
 ( 4 )e  ( 4  4 0.6 )e 4  0.6
9
9
9
5
8
5
 ( 2.221191545)  ( 218.3926001)  ( 8589.142689)
9
9
9
 4967.106689
(   4.79% )
1
Four-point formula
I   f ( x )dx  0.34785 f ( 0.861136)  f ( 0.861136)
1
1
 0.652145 f ( 0.339981)  f ( 0.339981)
 5197.54375
(   0.37% )
USC

similar documents