Lecture 09 Copyrigt by Hongyun Wang, UCSC Recap: Te total error in numerical differentiation fl( f ( x + fl( f ( x E T ( = f ( x Numerical result from a computer Exact value = e + f x+ Discretization error ( + f( x 3 Effect of round-off error Te total error diverges to infinity as goes to zero. Composite trapezoidal rule N 1 b f + f + f 0 N i = i=1 f ( x dx + E a Error Numerical approximation E( = O ( Exact value Composite Simpson rule N 1 N b 6 f + f + f 0 N i + 4 f i1/ = i=1 i =1 f ( x dx + E a Error E( = O ( 4 Numerical approximation (Draw tumerical grid to explain f i and f i1/. Exact value For boumerical differentiation and numerical integration, we ave Penalty for using very small Advantage for using iger order metod - 1 -
Numerical error estimation Consider te error in a numerical result: Error = Numerical result Exact value Question: How to estimate te error wen te exact value is unknown? Here we consider te situation were te total error is dominated by te discretization error and te effect of round-off error can beglected. We first introduce totation. Notation: Let T( be tumerical approximation to quantity I, obtained wit step size using a p-t order numerical metod. T( = I E were Numerical approximation + Exact value Error E( = C p + o ( p ==> T = I + C p + o ( p Example: Second order numerical differentiation metod for approximating f f ( x + f ( x = f ( x + E ( I Error T E( = C + o ( ( x: Example: Composite Simpson s rule for approximating b a f x dx - -
N 1 N 6 f + f + f 0 N i + 4 f i1/ i=1 i=1 = f( x dx + E( a Error T( I E( = C + o b Goal: to estimate E( wen te exact value of quantity I is unknown. Strategy: we calculate T( and T(/. T = I + C p + o p T = I + C p + o ( p ==> T T = 1 1 T T ==> C p = 1 1 p Using E( C p, we obtain T E p Cp + o p + o ( p T 1 1 p Tis is ow we estimate te error numerically wen te exact value is unknown. If p (te order of tumerical metod is unknown, we simply use ~ T E T Estimating te order of a metod E( C p E C p - 3 -
==> E E E ==> p log E AMS 147 Computational Metods and Applications p T ( T Using E( 1 1 p, we obtain T ( T p log T T 4 Tis is ow we estimate te order of accuracy of a numerical metod. Numerical solutions of ODEs Goal: to solve te initial value problem y = F y,t y( 0= y 0 We introduce tumerical grid = n, n = 0, 1,,, N t N = N= T were is called te time step. Te first metod we introduce is Euler metod. Euler metod: At, te differential equation is y ( = Fyt ( ( n, Strategy: use yt ( n+1 yt ( n to approximate y ( t n. yt ( ==> n+1 yt ( n Fyt ( ( n, - 4 -
==> yt ( n+1 yt ( n + F( y(, wic leads to te Euler metod y n+1 = y n + F( y n, y n : numerical approximation of y Note: te Euler metod is an explicit metod. To fully understand te difference between explicit metods and implicit metods, we introduce backward Euler metod, wic is an implicit metod. Backward Euler metod: At +1, te differential equation is y ( +1 = Fyt ( ( n +1, +1 Strategy: use yt ( n+1 yt ( n to approximate y ( t n +1. yt ( n+1 yt ( n Fyt ( ( n +1, +1 ==> yt ( n+1 yt ( n + F( y( +1,+1 wic leads to te backward Euler metod y n+1 = y n + F( y n+1, +1 Note: te backward Euler metod is an implicit metod. In te backward Euler metod, y n+1 is not given as an explicit expression. Instead, y n+1 is given as te solution of an equation. If function F(y, t is non-linear in y, te equation is a non-linear equation. Error analysis Notation: Exact solution y(t is a continuous function of t. Numerical solution {y 0, y 1, y,, y N } contains approximations at discrete times. Note: te size of numerical solution increases as time step is reduced. t N = N= T Global error: - 5 -
( = def y N yt N Numerical solution at t N Exact solution at t N were t N = N = T is fixed as 0. (Draw a grap of yt ( N and y N to sow te global error Goal of te error analysis: ( = y N yt ( N. To find te order of global error To acieve tat goal, we firseed to study te local truncation error. Local truncation error (LTE: Wen we substitute an exact solution of y = F y,t term is called te local truncation error. into tumerical metod, te residual Local truncation error (LTE of Euler metod: We write te Euler metod as y n+1 y n F( y n, = 0 Let yt be an exact solution of y = Fy,t. Te local truncation error (LTE is ( = yt ( n+1 yt ( n F( y(, We use te Taylor expansion to find te order of te local truncation error (LTE. We do Taylor expansion of yt ( n+1 = yt ( n + around. ( = y = + y ( + y ( y ( + = O ( + yt ( n F y(, Local truncation error (LTE of backward Euler metod We write te backward Euler metod as y n+1 y n F( y n+1, +1 = 0 Te local truncation error (LTE is ( = yt ( n+1 yt ( n F y( +1, +1-6 -
Again, we use te Taylor expansion to find te order of te local truncation error (LTE. We do Taylor expansion of yt ( n = yt ( n +1 around +1. ( = yt ( n+1 yt ( n +1 y ( +1 + y ( +1 + = y +1 + = O ( F y( +1, +1 Now we connect te local truncation error (LTE to te global error. Global error ( = y N yt ( N is wat we want to know. Local truncation error (LTE ( is wat we can derive using Taylor expansion. Question: How is ( related to (? Teorem: If ( = O ( p +1, ten ( = O ( p. Tat is, te global error is one order lower tan te local truncation error (LTE. (Te proof of te teorem is given in te Appendix. Using te teorem above, we examine te global error of Euler metod and te global error of backward Euler metod. Global error of Euler metod Local truncation error: ( = O ==> Global error ( = O ==> Euler metod is a first order metod. Global error of backward Euler metod: Local truncation error ( = O ==> Global error ( = O ==> Te backward Euler metod is a first order metod. For a first order metod, wen we reduce te time step by a factor of, te global error = O decreases only by a factor of. We like to ave iger order metods. - 7 -
Second order metods: At, te differential equation is y ( = Fyt ( ( n, Strategy: use yt ( n+1 yt ( n1 to approximate y (. yt ( ==> n+1 yt ( n1 F( y(, ==> yt ( n+1 yt ( n1 + F y(, wic leads to te midpoint metod. Te midpoint metod (also called te leap frog metod y n+1 = y n1 + F( y n, Local truncation error (LTE of te midpoint metod ( = yt ( n+1 yt ( n1 F y(, We do Taylor expansions of yt ( n+1 = yt ( n + and yt ( n1 = yt ( n around. ( = yt ( n + y( + y yt ( n y( + y = y ( 3 3! 3 + = O ( 3 + y ( 3 3! y ( 3 3! 3 + Global error of te midpoint metod is (by te teorem above ( = O 3 + F y (, ==> Te midpoint metod is a second order metod. Note: Te midpoint metod does not work well. It is numerically unstable. We will demonstrate its instability in computer illustration. A new approac (for constructing numerical metods Start wit te differential equation y = Fy,t - 8 -
Integrating from to +1, we ave +1 yt ( n+1 yt ( n = F( y(,t t dt Strategy: use te trapezoidal rule to approximate te integral on te rigt and side. yt ( n+1 yt ( n = F y (,, +1 wic leads to te trapezoidal metod. Te trapezoidal metod: y n+1 = y n + Fy n, ( + Fyt ( n+1 + O ( 3 ( + Fy ( n+1, +1 Local truncation error of te trapezoidal metod is ( = yt ( n+1 yt ( n F ( y (, + F y( +1, +1 = O ( 3 ( (based on te discretization error of te trapezoidal rule. Global error of te trapezoidal metod is (by te teorem above ( = O ==> Te trapezoidal metod is a second order metod. Note: te trapezoidal metod is an implicit metod. - 9 -
Appendix Teorem: If ( = O ( p +1, ten ( = O ( p. Proof of te teorem: To prove te teorem, weed to look at anoter type of error. Error of one step: Let y ( t be te exact solution of Error of one step is defined as y = F y,t. yt ( n = y n e n ( def = y ( +1 y n +1 (Draw a grap of y n+1 and y ( +1 to sow te error of one step For te Euler metod (as a representative of explicit metods, we ave e n ( = y ( +1 y n+1 = y ( +1 y n F( y n, = y ( +1 y ( F( y (, = ( For explicit metods, error of one step is te same as local truncation error. For te backward Euler metod (as a representative of implicit metods, we ave e n ( = y ( +1 y n+1 = y ( +1 y n F( y n+1, +1 = y ( +1 y ( F( y ( +1,+1 + F ( y ( +1,+1 F ( y n+1, +1 = ( + F y = ( + F y e n ( ( y ( +1 y n+1 ==> e n ( 1 F = e y n ==> 1 ( = ( 1 F y = 1 + F y + O - 10 -
In general, error of one step and local truncation error ave te same leading term. Wit te elp of error of one step, wow write out te proof of te teorem. E 0 ( = 0 E n +1 ( = yt ( n +1 y n +1 = yt ( n +1 y ( +1 y ( +1 y n +1 + ( + ==> E n +1 ( y+1 y +1 y ( +1 y n+1 (E01 Te second term on te rigt and side of (E01 is error of one step y ( +1 y n +1 = e n ( = Oe ( n ( = O p+1 ==> y ( +1 y n+1 C p +1 Te first term on te rigt and side of (E01 is te difference between two exact solutions. Bot yt and y ( t satisfy y = Fy,t. But tey ave different starting values at. Te teory of ODE tells us tat yt y ( t e ct y( y ( for t Setting t = +1 and =, we ave y +1 y +1 e c y Substituting tese into (E01, we get E n +1 y = e c yt ( n y n = e c E n ( ( e c E n ( + C p +1 (E0 Tis is a recursive inequality valid for all values of n. We are going to use it to estimate were N = T. Let = e c. Dividing bot sides of (E0 by n+1, we obtain E n +1 ( E n ( + C n+1 n p+1 1 n +1 Summing over n = 0,1,,, N 1, we get ( E 0( + C N 0 p+1 1 + 1 + + 1 N Recall tat te sum of a geometric series is given by 1 + r + + r N 1 = rn 1 r 1 (E03-11 -
==> 1 + 1 + + 1 = 1 N N ( 1 + + +N1 = 1 N Substituting it into (E03 and using E 0 ( = 0, we ave ( C p +1 N 1 1 N 1 1 (E04 Using te inequality e x 1 x, we obtain 1 = e c 1 c N 1 = e cn 1 = e ct 1 Tus, we arrive at ( C p +1 e ct 1 c = C ect 1 c p ==> ( = O ( p - 1 -