This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
PowerPoints organized by Dr. Michael R. Gustafson II, Duke UniversityRevised by Prof. Jang, CAU
Chapter ObjectivesChapter ObjectivesUnderstanding the meaning of local and global truncation• Understanding the meaning of local and global truncation errors and their relationship to step size for one-step methods for solving ODEs.K i h t i l t th f ll i R K tt (RK)• Knowing how to implement the following Runge-Kutta (RK) methods for a single ODE:– Euler
H– Heun– Midpoint– Fourth-Order RK
K i h i h f H ’ h d• Knowing how to iterate the corrector of Heun’s method.• Knowing how to implement the following Runge-Kutta
methods for systems of ODEs:y– Euler– Fourth-order RK
Ordinary Differential EquationsOrdinary Differential Equations• Conservation laws are presented in the form of differential
equationsequations. • Nth order differential equation can be reduced to first-order
differential equation.Methods described here are for sol ing differential eq ations of• Methods described here are for solving differential equations of the form: dy
dt f t, y
• The methods in this chapter are all one-step methods and have the general format:
dt
y y h
where is called an increment function, and is used to extrapolate from an old value y to a new value y h is the time step
yi1 yi h
from an old value yi to a new value yi+1. h is the time step.• One-step methods compute a future prediction yi+1 based only on
information at a single point yi
M l i h d f di i b d• Multi-step methods compute a future prediction yi+1 based on several previous points.
Euler’s MethodEuler s Method• The first derivativeThe first derivative
provides a direct estimate of the slope at ti: dy
dt ti
f ti , yi
and the Euler method uses that estimate as
ti
the increment
function: f ti , yi y y f t y hyi1 yi f ti , yi h
Example 20.1 (1/2)p ( / )Q. Use Euler Method to integrate y' = 4e0.8t – 0.5y =f from t = 0 to
4 ith t i f 1 Th i iti l diti t t 0 i 2 Th4 with a step size of 1. The initial condition at t = 0 is y = 2. The exact solution can be determined by
4 ttt eeey 5.05.08.0 2)(3.1
4
)1)(2,0()0()1( fyy
3)2(5.04)2,0( 0 ef 5)1(32)1( y
Euler’s method
19463.62)(3.1
4 )1(5.0)1(5.0)1(8.0 eeey
%28.19%10019463.6
519463.6
t
)1)(51()1()2( f
40216.11)1)](5(5.04[5
)1)(5,1()1()2()1(8.0
e
fyy
Example 20.1 (2/2)Example 20.1 (2/2)t ytrue yEuler (%)t
012
2.000006.1946314.84392
2.000005.0000011.40216
19.2823.19
34
33.6771775.33896
25.5132156.84931
24.2424.54
Error Analysis for Euler’s MethodError Analysis for Euler s Method• The numerical solution of ODEs involves twoThe numerical solution of ODEs involves two
types of error:– Truncation errors, caused by the nature of the
i ti t h i l dapproximation techniques employed– Roundoff errors, caused by the limited numbers of
significant digits that can be retaineds g ca t d g ts t at ca be eta ed• The total, or global truncation error can be
further split into:– local truncation error that results from an
application method in question over a single step, andand
– propagated truncation error that results from the approximations produced during previous steps.
Error Analysis for Euler’s MethodError Analysis for Euler s Method• The local truncation error for Euler’s method is
O(h2) and proportional to the derivative of f(t,y) while the global truncation error is O(h).
)1(
)(!
),(!2
),(),( 1
)1(2
1
nniin
iiiiii hOh
nytf
hytf
hytfyy
hytfyy iiii ),(1 )(),( 12
nii hOh
ytfE
• This means:– The global error can be reduced by decreasing the
)(!2
t hOhE
The global error can be reduced by decreasing the step size, and
– Euler’s method will provide error-free predictions if the nderl ing f nction is linear ( > secondthe underlying function is linear (-> second derivative is zero).
• Euler’s method is conditionally stable, depending u e s et od s co d t o a y stab e, depe d gon the size of h.
Stability of Euler Methody-
0 0 (0) atdy ay with y y y y edt
dt
1 1 (1 )ii i i i
dyy y h y y ahdt
Amplification factor : g = 1 ahAmplification factor : g = 1-ahIf |g|>1 (that is h > 2/a), the solution will grow in anunbound fashion.unbound fashion. -> Euler method is conditionally stable.
There are certain ODEs where errors always growregardless of the method -> ill-conditioned ODE
A fundamental source of error in Euler’s method is thatthe derivative at the beginning of the interval is assumedg gto apply across the entire interval.
MATLAB Code for Euler’s MethodMATLAB Code for Euler s Method
Heun’s MethodHeun s Method• One method to improve Euler’s method is to determine
derivatives at the beginning and predicted ending of the interval g g p gand average them:
0
),( iii ytfy
hytfyy iiii ),(01
),( 0111 iii ytfy
Predictor Eq.
hi li ki di i f h l f
hytfytf
yy iiiiii 2
),(),( 011
1
Corrector Eq.
• This process relies on making a prediction of the new value of y, then correcting it based on the slope calculated at that new value.
• This predictor-corrector approach can be iterated to convergence:s p ed cto co ecto app oac ca be te ated to co e ge ce:
hytfyy iimii ),(0
1
),(),( 111 h
ytfytf jii
miimj
),,2,1 (
2
111
mj
hyy iiiimi
ji
Example 20.2 (1/3)p ( / )Q. Use Heun’s method with iteration to integrate
y' = 4e0.8t – 0.5y from t = 0 to 4 with a step size of 1 The initial condition at t = 0 is y = 2size of 1. The initial condition at t = 0 is y = 2. The stopping criterion is 0.00001%.
Example 20 2 (2/3)Example 20.2 (2/3)Sol.) 2,0:IC 5.04 8.0 ytyey t
(t0, y0):
P di t
3)2(5.04 00 ey
Predictor: 19.28%: percent relative error (Euler)5)1(3201 y
With t it ti With it tiWithout iteration With iteration
t ytrue yEuler (%) yHeun (%) yHeun (%)
0 2 00000 2 00000 2 00000 2 00000t t t
012
2.000006.19463
14.84392
2.000005.00000
11.4021619.2823.19
2.000006.70108
16.319788.189.94
2.000006.36087
15.302242.683.09
34
33.6771775.33896
25.5132156.84931
24.2424.51
37.1992583.33777
10.4610.62
34.7432877.73510
3.173.18
Midpoint MethodMidpoint Method• Another improvement to Euler’s method is similar
to Heun’s method but predicts the slope at theto Heun s method, but predicts the slope at the midpoint of an interval rather than at the end:
h2
),(2/1hytfyy iiii
)( 2/12/12/1 iii ytfy ),( 2/12/12/1 iii ytfy
hytfyy iiii ),( 2/12/11
• The midpoint method is superior to Euler’s method in the same way that centered difference is better approximation rather than either forward or backward versions. This method has a local t ti f O(h3) d l b l f O(h2)truncation error of O(h3) and global error of O(h2).
Runge-Kutta MethodsRunge Kutta Methods• Runge-Kutta (RK) methods achieve the accuracy of a Taylor
series approach without requiring the calculation of higher pp q g gderivatives.
• For RK methods, the increment function can be generally written as: a k a k a k
(1) 1 hyy ii
written as:
where the a’s are constants and the k’s are
a1k1 a2k2 ankn
ytfk ii1 , hkqhkqyhptfk
hkqyhptfkytfk
ii
ii
ii
22212123
11112
1
, ,
,
where the p’s and q’s are constants. hkqhkqhkqyhptfk nnnnninin 11,122,111,11 ,
• First order RK method with n=1: Euler’s method• Once n is chosen, values for the a’s, p’s, and q’s are evaluated
by setting Eq (1) equal to terms in Taylor series expansionby setting Eq. (1) equal to terms in Taylor series expansion.
Second order Runge KuttaSecond-order Runge-KuttaThe second order version of Eq. (1) is
hkakayy ii )( 22111
),(1 ii ytfk
)( hkhfk ),( 11112 hkqyhptfk ii
The values for a1, a2, p1 and q11 are evaluated by setting E (1) l d d T l i
21 !2
),(),( h
ytfhytfyy ii
iiii
dtdy
yytf
tytfytf ii
),(),(),(
Eq. (1) equal to a second order Taylor series.
!2
!2),(
2
1h
dtdy
yf
tfhytfyy iiii
dtyt
y
hkakayy ii )( 22111
Second order Runge KuttaSecond-order Runge-Kutta
gsgrytgsyrtg )()( hkakayy )(
y
st
rytgsyrtg ),(),( hkakayy ii )( 22111
),( 11112 hkqyhptfk ii
)(),(),( 211111111 hO
yfhkq
tfhpytfhkqyhptf iiii
)(),(),(),( 32112
212211 hO
yfytfhqa
tfhpaythfaythfayy iiiiiiii
)(),(),(),( 3211212211 hOh
yfytfqa
tfpahytfaytfayy iiiiiiii
1
2/12/11
12
21
qapa
aaFour unknownsThree eq.
21 1 aa 2
111 21a
qp
There are an infinite number of second-2/1112 qaorder RK methods.
Second order Runge KuttaSecond-order Runge-Kutta
• Heun method without iteration– a2 = 1/2 a1 = 1/2 and p1 = q11 = 1a2 / a1 / a d p1 q11
hkkyy ii
211 2
121 ),(1 ii ytfk
)( hkyhtfk
• Midpont method
22 ),( 12 hkyhtfk ii
– a2 = 1 a1 = 0 and p1 = q11 = 1/2
hkyy )(fkhkyy ii 21 ),(1 ii ytfk )2/,2/( 12 hkyhtfk ii
Classical Fourth order RKClassical Fourth-order RK• Classical Fourth-order RK
– The most popular RK method
hkkkkyy ii 43211 2261
6
),(1 ii ytfk
hkyhtfk ii 12 2
1,21
22
hkyhtfk ii 23 2
1,21
– The fourth-order RK method is i il t th H th d i
hkyhtfk ii 34 ,
similar to the Heun method in that multiple estimates of the slop are used.
Example 20.3 (1/2)p ( / )Q. Use the classical fourth-order RK to integrate the following
f ti f t 0 t 1 ith t i f 1 d i iti l ditifunction from t = 0 to 1 with a step size of 1 and initial condition is y(0) = 2.
Sol ) ytfyey t ,5.04 8.0
Sol.)the slope at the beginning3)2(5.04)2,0( )0(8.0
Example 20 3 (2/2)Example 20.3 (2/2)912974.5)0.1(912974.3230 hky
the slope at the end
)(30y0.8(0.5)
4 (1.0, 5.912974) 4 0.5 (5.912974) 5.945677k f e
the average slope
201037.4945677.5)912974.3(2)217299.4(2361
g p
final prediction(1.0) 2 4.201037 (1.0) 6.201037y
p
= 0 103% where the exact solution is 6 194631t = 0.103% where the exact solution is 6.194631.
Systems of EquationsSystems of Equations• Many practical problems require the solution y p p q
of a system of equations:dy1
d f1 t, y1, y2 ,, yn
dtf1 , y1, y2 , , yn
dy2
dt f2 t, y1, y2 ,, yn
dt
dyn
dt fn t, y1, y2 ,, yn
• The solution of such a system requires that ninitial conditions be known at the starting
dt n 1 2 n
initial conditions be known at the starting value of t.
Solution MethodsSolution Methods• Single-equation methods can be used to g q
solve systems of ODE’s as well; for example Euler’s method can be used onexample, Euler s method can be used on systems of equations - the one-step method is applied for every equation atmethod is applied for every equation at each step before proceeding to the next step.
• Fourth-order Runge-Kutta methods canFourth order Runge Kutta methods can also be used, but care must be taken in calculating the k’scalculating the k s.
Example 20.4 (1/3)p ( / )Q. Solve for the velocity and position of the free falling
b j i E l th d Th i iti l ditibungee jumper using Euler method. The initial condition for t = 0, x = v = 0. The step size is 2s and integrate up to t = 10s g= 9 81 m/s2 m= 68 1 kg cd= 0 25 kg/mto t = 10s. g= 9.81 m/s , m= 68.1 kg, cd= 0.25 kg/m.