Download Trapezoid Method - KFUPM Faculty List

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CISE301: Numerical Methods
Topic 7
Numerical Integration
Lecture 24-27
KFUPM
Read Chapter 21, Section 1
Read Chapter 22, Sections 2-3
CISE301_Topic7
KFUPM
1
Lecture 24
Introduction to Numerical
Integration






Definitions
Upper and Lower Sums
Trapezoid Method (Newton-Cotes Methods)
Romberg Method
Gauss Quadrature
Examples
CISE301_Topic7
KFUPM
2
Integration
Definite Integrals
Indefinite Integrals
1
2
x
 x dx  2  c
x
0 xdx  2
Indefinite Integrals of a
function are functions
that differ from each
other by a constant.
CISE301_Topic7
2 1
0
1

2
Definite Integrals are
numbers.
KFUPM
3
Fundamental Theorem of Calculus
If f is continuous on an interval [a,b] ,
F is antiderivative of f

b
a
(i.e., F ' ( x)  f ( x) )
f(x)dx  F(b)  F(a)
There is no antiderivative for: e
No closed form solution for:
CISE301_Topic7

KFUPM
b
a
x2
x2
e dx
4
The Area Under the Curve
One interpretation of the definite integral is:
Integral = area under the curve
f(x)
Area  
a
CISE301_Topic7
b
a
f(x)dx
b
KFUPM
5
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
CISE301_Topic7
KFUPM
b
6
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
Estimate of the integral 
Error 
L U
2
U L
2
x0 x1 x2 x3
CISE301_Topic7
KFUPM
a
b
7
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
xi 1  xi 
4
CISE301_Topic7
for i  0,1, 2, 3
0
KFUPM
1
4
1
2
3
4
1
8
Example
n 1
Lower sum L( f , P )   mi  xi 1  xi 
i 0
L( f , P ) 
1
1 1 9  14
0

  

4  16 4 16  64
n 1
Upper sum U ( f , P )   M i  xi 1  xi 
i 0
U ( f , P) 
11 1 9
 30



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
CISE301_Topic7
KFUPM
0
1
4
1
2
3
4
1
9
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.
CISE301_Topic7
KFUPM
10
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.



b
a
b
a
f ( x)dx 

b
a
n
a

a
x

...

a
x
0 1
 dx
n
(b 2  a 2 )
(b n 1  a n 1 )
f ( x)dx  a0 (b  a )  a1
 ...  an
2
n 1
CISE301_Topic7
KFUPM
11
Newton-Cotes Methods

Trapezoid Method (First Order Polynomials are used)
b
a

f ( x)dx  
b
a
a0  a1x dx
Simpson 1/3 Rule (Second Order Polynomials are used)
b
a
CISE301_Topic7
f ( x)dx  
b
a
a
0
KFUPM

 a1x  a2 x dx
2
12
Lecture 25
Trapezoid Method




Derivation-One Interval
Multiple Application Rule
Estimating the Error
Recursive Trapezoid Method
Read 21.1
CISE301_Topic7
KFUPM
13
Trapezoid Method
b
f (b)  f (a)
f (a) 
( x  a)
ba
f(x)
I   f ( x)dx
a
f (b)  f (a )


I    f (a) 
( x  a ) dx
a
ba


b
b
f (b)  f (a ) 

  f (a)  a
x
ba

 a
2 b
f (b)  f (a ) x

ba
2
a
CISE301_Topic7
b
 b  a 
KFUPM
a
f (b)  f (a )
2
14
Trapezoid Method
Derivation-One Interval
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
b
b
2 b
f (b)  f (a ) 
f (b)  f (a ) x

  f (a)  a
x 
ba
ba
2

 a
a
f (b)  f (a ) 
f (b)  f (a ) 2

  f (a)  a
(b  a 2 )
b  a  
ba
2(b  a )


f (b)  f (a )
 b  a 
2
CISE301_Topic7
KFUPM
15
Trapezoid Method
f(x)
f (b )
f (a )
ba
 f (a)  f (b) 
Area 
2
a
CISE301_Topic7
b
KFUPM
16
Trapezoid Method
Multiple Application Rule
The interval
[a, b] is
f(x)
f ( x2 )  f ( x1 )
x2  x1 
Area 
2
partitione d into n segments
a  x0  x1  x2  ...  xn  b

b
a
f ( x)dx  sum of the areas
of the trapezoid s
x
x0
a
CISE301_Topic7
KFUPM
x1
x2
x3
b
17
Trapezoid Method
General Formula and Special Case
If the interval is divided into n segments (not necessaril y equal)
a  x0  x1  x2  ...  xn  b

n 1
1
f ( x)dx    xi 1  xi  f ( xi 1 )  f ( xi ) 
i 0 2
b
a
Special Case ( Equalliy spaced base points)
xi 1  xi  h for all i

b
a
n 1
1

f ( x)dx  h   f ( x0 )  f ( xn )    f ( xi ) 
i 1
2

CISE301_Topic7
KFUPM
18
Example
Given a tabulated
values of the velocity of
an object.
Time (s)
0.0
1.0
2.0
3.0
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
Distance 
CISE301_Topic7

3
0
V (t ) dt
KFUPM
19
Example 1
The interval is divided
Time (s)
0.0
1.0
2.0
3.0
into 3 subinterva ls
Velocity
(m/s)
0.0
10
12
14
Base points are0,1,2,3
Trapezoid Method
h  xi 1  xi  1
1
 n 1

T  h  f ( xi )   f ( x0 )  f ( xn ) 
2
 i 1

1


Distance  1(10  12)  (0  14)  29
2


CISE301_Topic7
KFUPM
20
Estimating the Error
For Trapezoid Method
How many equally spaced intervals are
needed to compute


0
sin( x)dx
to 5 decimal digit accuracy ?
CISE301_Topic7
KFUPM
21
Error in estimating the integral
Theorem
Assumption :
f ' ' ( x) is continuous on [a,b]
Equal intervals (width  h)
Theorem :
approximat e
If Trapezoid Method is used to

b
a
f ( x)dx
then
b  a 2 ''
Error  
h f ( ) where   [a,b]
12
ba 2
Error 
h max f ' ' ( x)
x[ a ,b ]
12
CISE301_Topic7
KFUPM
22
Example


0
sin( x)dx,
1
find h so that error   10 5
2
ba 2
Error 
h max f ' ' ( x)
x[ a ,b ]
12
b   ; a  0; f ' ( x)  cos( x); f ' ' ( x)   sin( x)

1
f ' ' ( x)  1  Error  h   10 5
12
2
6
2
5

h   10
2

CISE301_Topic7
KFUPM
23
Example
x
1.0
1.5
2.0
2.5
3.0
f(x)
2.1
3.2
3.4
2.8
2.7
Use Trapezoid method to compute :

3
1
f ( x)dx
n 1
1
Trapezoid T ( f , P)    xi 1  xi  f ( xi 1 )  f ( xi ) 
i 0 2
Special Case : h  xi 1  xi for all i,
1
 n 1

T ( f , P)  h  f ( xi )   f ( x0 )  f ( xn ) 
2
 i 1

CISE301_Topic7
KFUPM
24
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
1
CISE301_Topic7
n1

1
f ( x)dx  h  f ( xi )   f ( x0 )  f ( xn ) 
2
 i 1

1


 0.5  3.2  3.4  2.8  2.1  2.7 
2


 5.9
KFUPM
25
Recursive Trapezoid Method
Estimate based on one interval :
f(x)
h ba
ba
 f (a)  f (b) 
R (0,0) 
2
a
CISE301_Topic7
KFUPM
ah
26
Recursive Trapezoid Method
Estimate based on 2 intervals :
h
ba
2
Recall special
case of Trapezoid
Method!!
f(x)
R (1,0) 
ba 
1



f
(
a

h
)

f
(
a
)

f
(
b
)

2 
2

R (1,0) 
1
R (0,0)  h f (a  h)
2
Based on previous estimate
a
ah
a  2h
Based on new point
CISE301_Topic7
KFUPM
27
Recursive Trapezoid Method
f(x)
ba
h
4
R (2,0) 
R(2,0) 
ba
 f (a  h)  f (a  2h)  f (a  3h)
4
1

  f (a )  f (b) 
2

1
R(1,0)  h f (a  h)  f (a  3h)
2
a
Based on previous estimate
a  2h
a  4h
Based on new points
CISE301_Topic7
KFUPM
28
Recursive Trapezoid Method
Formulas
ba
 f (a)  f (b)
R (0,0) 
2


1
R (n,0)  R (n  1,0)  h   f a  (2k  1)h 
2
 k 1

2 ( n1)
ba
h n
2
CISE301_Topic7
KFUPM
29
Recursive Trapezoid Method
ba
,
2
ba
 f (a)  f (b)
2
1
1

R(1,0)  R(0,0)  h  f a  (2k  1)h 
2
 k 1

ba
h 2 ,
2
1
 2

R(2,0)  R(1,0)  h  f a  (2k  1)h 
2
 k 1

ba
h 3 ,
2
2

1
R(3,0)  R(2,0)  h  f a  (2k  1)h 
2
 k 1

h  b  a,
h
R (0,0) 
2
..................
h
ba
,
n
2
CISE301_Topic7
2

1
R(n,0)  R(n  1,0)  h   f a  (2k  1)h 
2
 k 1

( n 1)
KFUPM
30
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.
CISE301_Topic7
KFUPM
31
Lecture 26
Romberg Method





Motivation
Derivation of Romberg Method
Romberg Method
Example
When to stop?
Read 22.2
CISE301_Topic7
KFUPM
32
Motivation for Romberg Method

Trapezoid formula with an interval h gives an
error of the order O(h2).

We can combine two Trapezoid estimates with
intervals 2h and h to get a better estimate.
CISE301_Topic7
KFUPM
33
Romberg Method
Estimates using Trapezoid method with intervals of size h, 2h, 4h,8h,...
are combined to improve the approximation of
First column is obtained
using Trapezoid Method

b
a
f ( x) dx
R(0,0)
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
CISE301_Topic7
KFUPM
34
First Column
Recursive Trapezoid Method
ba
 f (a)  f (b)
R (0,0) 
2


1
R (n,0)  R (n  1,0)  h   f a  (2k  1)h 
2
 k 1

2 ( n1)
ba
h n
2
CISE301_Topic7
KFUPM
35
Derivation of Romberg Method


b
a
b
a
ba
Trapezoid method with h  n 1
2
f ( x)dx  R(n  1,0)  O(h )
2
f ( x)dx  R(n  1,0)  a2 h 2  a4 h 4  a6 h 6  ...
(eq1)
More accurate estimate is obtained by R(n,0)
1
1
1
2
4
6
f
(
x
)
dx

R
(
n
,
0
)

a
h

a
h

a
h
 ...
2
4
6
a
4
16
64
eq1  4 * eq 2
gives
b

b
a
(eq 2)
1
f ( x)dx  R(n,0)  R(n,0)  R(n  1,0)  b4 h 4  b6 h 6  ...
3
CISE301_Topic7
KFUPM
36
Romberg Method
ba
R(0,0)
 f (a)  f (b)
R (0,0) 
R(1,0) R(1,1)
2
R(2,0) R(2,1)
ba
h n ,
R(3,0) R(3,1)
2
2 ( n1)


1
R(n,0)  R(n  1,0)  h   f a  (2k  1)h 
2
 k 1

R(2,2)
R(3,2)
R(3,3)
1
R(n, m)  R(n, m  1)  m R(n, m  1)  R(n  1, m  1)
4 1
for n  1, m  1
CISE301_Topic7
KFUPM
37
Property of Romberg Method
R(0,0)
Theorem
b

R(1,0) R(1,1)
f ( x)dx  R(n, m)  O(h 2 m  2 )
R(3,0) R(3,1) R(3,2) R(3,3)
a
Error Level
CISE301_Topic7
R(2,0) R(2,1) R(2,2)
O( h 2 )
KFUPM
O(h 4 )
O( h 6 )
O( h 8 )
38
Example 1
Compute
1
0
x 2 dx
0.5
ba
1
 f (a)  f (b)  0  1  0.5
h  1, R (0,0) 
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)  R (n, m  1) 
1
4 1
for n  1, m  1
R (1,1)  R (1,0) 
CISE301_Topic7
1
41  1
m
3/8 1/3
R(n, m  1)  R(n  1, m  1)
R(1,0)  R(0,0)  3  1  3  1   1
8
KFUPM
3 8
2
3
39
Example 1 (cont.)
0.5
3/8
1/3
11/32
1/3
1
1
h  , R (2, 0)  R(1, 0)  h( f (a  h)  f (a  3h)) 
4
2
1/3
1  3  1  1 9  11
     
2  8  4  16 16  32
1
 R(n, m  1)  R(n  1, m  1) 
m
4 1
1
11 1  11 3  1
R (2,1)  R(2, 0)  1  R(2, 0)  R(1, 0)  
   
4 1
32 3  32 8  3
1
1 1 1 1  1
R (2, 2)  R(2,1)  2  R(2,1)  R(1,1)       
4 1
3 15  3 3  3
R (n, m)  R (n, m  1) 
CISE301_Topic7
KFUPM
40
When do we stop?
STOP if
R(n, m  1)  R(n  1, m  1)  
or
After a given number of steps,
for example, STOP at R(4,4)
CISE301_Topic7
KFUPM
41
Lecture 27
Gauss Quadrature


Motivation
General integration formula
Read 22.4
CISE301_Topic7
KFUPM
42
Motivation
Large overall
error
Figure 22.6, p. 641
Smaller
overall error
CISE301_Topic7
KFUPM
43
Motivation (Contd.)
Trapezoid Method:
1
 n 1

f ( xi )   f ( x0 )  f ( xn )  
 a f ( x)dx  h  
2
i 1

It can be expressed as:
b

b
a
n
f ( x)dx   ci f ( xi )
i 0
 h
where ci  
 0.5 h
CISE301_Topic7
i  1, 2,..., n  1
i  0 and n
KFUPM
44
General Integration Formula

b
a
n
f ( x)dx   ci f ( xi )
ci : Weights
i 0
xi : Nodes
Question :
Can we select ci and xi so that the formula gives a
better approximation of the integral?
CISE301_Topic7
KFUPM
45
Question
What is the best way to choose the nodes
and the weights?
CISE301_Topic7
KFUPM
46
Question (Contd.)
• From previous figure, the integration is exact for a
polynomial of order  3 with 4 points (c0, c1, x0, and x1)
• Integrate each of the four f(x) polynomials (1, x, x 2 , x 3 )

1
1
• Solve for c0, c1, x0, and x1  c0 = c1 = 1, x0 = 
, x1 =
3
3
CISE301_Topic7
KFUPM
47
Gauss–Legendre Quadrature
(generalization of previous example)
An n-point Gauss-Legendre Quadrature rule is constructed to yield an exact result for
− 1 or less by a suitable choice of the points x and
weights c for i = 1, ..., n.
polynomials of degree 2n
i
i

b
a
n
f ( x)dx   ci f ( xi )
i 0
where ci 
2
(1  x )  Pn( xi ) 
2
2
i
,
 n  k 1 
n
k  n
Pn ( x)  2   x  
2 

k 0
 k 
n


n
Source:
CISE301_Topic7
and
KFUPM
48
Gauss–Legendre Quadrature
See more in Table 22.1 (page 646)

1
1
n
f ( x)dx  ci f ( xi )
n 1
i 0
x0  0.57735, x1  0.57735
(2 pts.) c0  1,
c1  1
n  2 x0  0.774596, x1  0.000000, x2  0.774596
(3 pts.) c0  0.555556,
c1  0.888889, c2  0.555556
n  3 x0  0.86113, x1  0.33998, x2  0.33998, x3  0.86113
(4 pts.) c0  0.34785,
c1  0.65214, c2  0.65214, c3  0.34785
n  4 x0  0.906179, x1  0.538469, x2  0.00000, x3  0.538469, x4  0.906179
(5 pts.) c0  0.236926,
CISE301_Topic7
c1  0.478628, c2  0.568889, c3  0.478628, c4  0.236926
KFUPM
49
Error Analysis for Gauss Quadrature
Let the integral

b
a

b
a
f ( x) dx be approximated by:
n
f ( x)dx   ci f ( xi )
i 0
where ci and xi are selected according to
the Gauss Quadrature formula,
Then, the true error satisfies:
Error 
22n 3  (n  1)! 4
(2n  3)  (2n  2)!
3
f (2 n  2) ( ),
  [1,1]
The formula will be exact for all polynomials of order  2n  1
CISE301_Topic7
KFUPM
50
Example

Evaluate
1
0
e
 x2
dx using Gaussian Quadrature with n  1.
 1
 1
(i.e. using  f ( x)dx  c0 f  x0   c1 f  x1   f     f 
 )
1
 3
 3
1
b
How do we use the formula to compute:  f ( x)dx
a
for arbitrary a and b?

CISE301_Topic7
b
a
ba
f ( x)dx 
2
ba
ba
 1 f  2 t  2 dt
1
KFUPM
51
Example

1  x2
e dx
0
1

2
1
 1 e
.5t .5 
 
 0.5
1  
 e
2 

CISE301_Topic7
2
dt

1
.5 
3

2
KFUPM


1
 0.5 .5 
3

e 
2





52
Improper Integrals
Methods discussed earlier can not be used directly to
approximat e improper integrals (one of the limits is  or  )
 Use a transform ation like the following
1 1
 a f ( x)dx   t 2 f  t dt , (assuming ab  0)
and apply the method on the new function.
b
Example :
CISE301_Topic7
1
a
1
b

1

1
1
dx  
2
0
x




1 1 
dt
2 
2 
t 1
  
 t 
  
KFUPM
53
Related documents