Professional Documents
Culture Documents
Lecture 09
Lecture 09
Lecture 09
Copyright by Hongyun Wang, UCSC
Recap:
E T ( h) =
fl( f (x + h )) fl( f ( x ))
)
f
( x
h
Exact
value
Numerical result
from a computer
e(h) +
f ( x + h) + f ( x) 3
h
Discretization
Effect of
round-off error
error
Numerical
approximation
Exact
value
( )
E (h) = O h2
Numerical
approximation
Exact
value
( )
E (h) = O h4
T ( h) = I + E ( h )
Numerical
approximation
Exact
value
Error
where
( )
E (h) = C h p + o h p
==>
T ( h ) = I + C h + o( h
p
Example:
Second order numerical differentiation method for approximating f ( x ) :
f ( x + h ) f ( x h)
= f ( x ) + E (h )
2h
I
T h
Error
( )
E (h) = C h2 + o h2
Example:
b
f ( x ) dx
a
-2-
T (h)
( )
E (h) = C h2 + o h2
T ( h ) = I + C h p + o( h p )
h
h
T = I + C + o( h p )
2
2
p
==>
==>
p
h 1
C h p + o( h p )
T (h ) T
= 1
2 2
Chp =
T (h ) T
1
h
2
1
2
+ o( h p )
Using E ( h ) C h p , we obtain
E ( h)
T ( h) T
1
h
2
1
2
This is how we estimate the error numerically when the exact value is unknown.
If p (the order of the numerical method) is unknown, we simply use
h
E ( h) ~ T (h ) T
2
Estimating the order of a method
E (h) C h p
h
h
E C
2
2
-3-
==>
E (h)
p log 2
h
E
2
==>
Using E ( h )
h
T (h) T
2
1
1
2
, we obtain
h
T ( h) T 2
p log2
T h T h
2
4
This is how we estimate the order of accuracy of a numerical method.
tn = n h
where h is called the time step.
The first method we introduce is Euler method.
Euler method:
At tn, the differential equation is
y ( tn ) = F ( y (tn ),tn )
Strategy: use
y (t n+1 ) y( tn )
to approximate y ( tn ) .
h
==>
y (t n+1 ) y( tn )
F ( y (tn ),tn )
h
==>
y (t n+1 ) y( tn ) + h F ( y ( tn ),t n )
-4-
y n+1 = y n + h F ( y n ,t n )
y n : numerical approximation of y( tn )
Note: the Euler method is an explicit method.
To fully understand the difference between explicit methods and implicit methods, we introduce
backward Euler method, which is an implicit method.
Backward Euler method:
At tn+1, the differential equation is
y ( tn +1 ) = F ( y (tn +1 ),tn +1 )
Strategy: use
y (t n+1 ) y( tn )
to approximate y ( tn +1 ) .
h
y (t n+1 ) y( tn )
F ( y (tn +1 ),tn +1 )
h
y (t n+1 ) y( tn ) + h F ( y ( tn+1 ),t n+1)
==>
Numerical solution {y0, y1, y2, } contains approximate solutions at discrete times.
Global error:
def
EN ( h ) =
y (t N )
y
N
Numerical
solution at t N
Exact
solution at t N
where t N = Nh = T is fixed as h 0 .
(Draw a graph of y (t N ) and y N to show the global error)
-5-
We use the Taylor expansion to find the order of the local truncation error (LTE).
We do Taylor expansion of y (t n+1 ) = y( tn + h ) around tn.
y (tn ) 2
en ( h) = y ( tn ) + y (tn ) h +
h + y (t n ) h F ( y ( tn ),t n )
2
=
y ( tn ) 2
2
h + = O( h )
2
Again, we use the Taylor expansion to find the order of the local truncation error (LTE).
We do Taylor expansion of y (t n ) = y( tn +1 h) around tn+1.
y (tn +1 ) 2
en ( h) = y ( tn+1 ) y (tn +1 ) y (tn +1 ) h +
h + h F ( y (tn +1 ),tn +1 )
2
=
y ( t n +1 ) 2
h + = O h2
2
( )
Now we connect the local truncation error (LTE) to the global error.
-6-
Local truncation error (LTE) en ( h ) is what we can derive using Taylor expansion.
==>
==>
==>
==>
For a first order method, when we reduce the time step h by a factor of 2, the global error
E N ( h) = O(h ) decreases only by a factor of 2. We like to have higher order methods.
Second order methods:
At tn, the differential equation is
y ( tn ) = F ( y (tn ),tn )
Strategy: use
y ( t n +1 ) y ( t n 1 )
2h
to approximate y ( tn ) .
==>
y ( t n +1 ) y ( t n 1 )
==>
y ( t n +1 ) y ( t n 1 ) + 2h F ( y ( t n ) ,t n )
2h
F ( y ( t n ) ,t n )
-7-
Note: The midpoint method does not work well. It is numerically unstable.
We will demonstrate its instability in computer illustration.
A new approach (for constructing numerical methods)
Start with the differential equation
y = F ( y,t)
Integrating from tn to tn+1, we have
y ( t n +1 ) y ( t n ) =
tn+1
F ( y (t ),t ) dt
tn
Strategy: use the trapezoidal rule to approximate the integral on the right hand side.
y (t n+1 ) y( tn ) =
h
F ( y (tn ),tn ) + F ( y ( tn+1 ),tn +1 ) + O( h 3 )
2
y n+1 = y n +
h
( F ( y n,t n ) + F ( y n+1,tn +1))
2
( )
en ( h ) = O h 3 .
==>
==>
-8-
Appendix
Theorem:
If en ( h) = O(h p +1 ) , then E N ( h) = O(h p ) .
Proof of the theorem:
To prove the theorem, we need to look at another type of error.
Error of one step:
y = F ( y,t )
.
Let y (t ) be the exact solution of
y ( tn ) = y n
en ( h) = y (tn +1 ) y n +1
def
(Draw a graph of y n+1 and y (tn +1 ) to show the error of one step)
For the Euler method (as a representative of explicit methods), we have
en ( h) = y ( tn+1 ) y n+1
= y( tn +1 ) y n h F ( y n ,tn )
= y( tn +1 ) y (t n ) h F ( y( tn ),t n ) = e n (h )
For explicit methods, error of one step is the same as local truncation error.
For the backward Euler method (as a representative of implicit methods), we have
en ( h) = y ( tn+1 ) y n+1
= y( tn +1 ) y n h F ( y n+1,tn +1 )
F
( y( tn +1) y n+1 )
y
= en (h ) + h
F
e (h )
y n
==>
F
en ( h) 1 h = e n (h )
y
==>
en ( h) = e n (h)
F
2
= en (h )1 + h
+ O(h )
y
F
1 h
y
1
-9-
E 0 ( h) = 0
E n +1 (h ) = y (tn +1 ) y n +1
= (y ( tn +1 ) y (t n+1)) + ( y (tn +1 ) y n +1 )
==>
(E01)
The second term on the right hand side of (E01) is error of one step
y (t n+1 ) yn +1 = en (h ) = O(en ( h)) = O(h p+1 )
==>
y( tn +1 ) y n+1 C2 h p +1
The first term on the right hand side of (E01) is the difference between two exact solutions.
Both y (t ) and y (t) satisfy y = F ( y,t) . But they have different starting values at tn.
The theory of ODE tells us that
c t
y ( t) y ( t) e ( ) y ( ) y ( )
for t
(E02)
This is a recursive inequality valid for all values of n. We are going to use it to estimate
E N (h ) where N h = T .
n+1
ch
Let = e . Dividing both sides of (E02) by , we obtain
E n +1 ( h)
E n ( h)
p+1 1
+ C2 h
n+1
n
n +1
E N (h )
E 0 ( h)
1
1
p+1 1
+ C2 h + 2 + + N
N
0
Recall that the sum of a geometric series is given by
1 + r + + r
N 1
rN 1
=
r 1
- 10 -
(E03)
==>
1
1
1
1 1
+ 2 + + N = N (1+ + + N 1 ) = N
N 1
1
E N (h ) C2 h
p +1
N 1
1
(E04)
x
Using the inequality e 1 x , we obtain
1 = e c h 1 ch
N 1 = e c N h 1 = e cT 1
Thus, we arrive at
E N (h ) C2 h
==>
p +1
e cT 1
e cT 1 p
ch = C c h
E N ( h ) = O (h p )
- 11 -