Professional Documents
Culture Documents
Chapter 7 - Numerical Methods For Initial Value Problems
Chapter 7 - Numerical Methods For Initial Value Problems
Chapter 7 - Numerical Methods For Initial Value Problems
Last lecture:
Improper Integral
This lecture:
Adaptive Integration
ODE—Initial value problems
Taylor series solution
Euler explicit method
CHAPTER VII
Objectives: Develop various accurate & efficient methods for solving ODEs’ such as
y' = f(x, y) (1)
Initial-Value & Boundary-Value problems
The Initial-value Conditions ---
ALL conditions are given at the same value of the independent variable (t).
du
For example at t = 0, u = 0.5 & = 1.0
dt
1
u = 0.5 &
du 0.5
= 1.0
dt
@t = 0
o t
t=0
Initial-Value & Boundary-Value Conditions
The B-V Conditions--- Conditions are given at different values
of the independent variable (x).
e.g. at x = 0, y = 1& at x = 2, y = 2.
2-D heat conduction
y
1-D heat conduction T=75
y=2
T=90 T=15 T=100 T=0
y=1
0 2 x T=25
o x=0 x=2 x
The numerical schemes for solving Initial-value and boundary-value problems are different.
7.1 Taylor series expansion for ODE
so that 𝑦0"′ = 3.
Taylor series expansion for ODE y' = -2x - y (= f(x, y) )
* Thus, Taylor series is not used for obtaining numerical solution to the ODEs.
7.2 Euler & Modified Euler Methods for y' = f(x, y), y0 = y(x0)
- 2 𝑦n" h +…
𝑦𝑛+1 −𝑦𝑛 1
Forward difference for y': 𝑦𝑛′ = ℎ
y
y(xn+1) y(x) Run: h
error {
yn+1 Rise: hyn′
* Note, since we start from n=1, after n time steps, the global error at xn+1 is: nh2 ~ O(h).
Hence, the Euler method has ONLY a first order accuracy
Example:
* Example: Solve y' = -2x -y, y(0) = -1 using Euler explicit scheme.
xn yn yn' yexact(xn) y(TS) yexact- yn
0 -1 1
0.1 -0.9 0.7
0.2 -0.83 0.43
0.3 -0.787 0.183
0.4 -0.7683 -0.0317 -0.81096 -0.8112 -0.04266
0.5 -0.77147 -0.22853
0.6 -0.794323 -0.405677
0.7 -0.8348907 -2.2348907
0.8 -1.0583798 -0.947986 -0.9552 0.110394
* Comments:
i. Error is relatively large at x=0.4 with only 4 time steps:
T.E.(x=0.4) = -0.04266.
ii. In order to reduce the T.E., say by a factor of 100, we need to reduce h by 100 which means an
increase in computational effort by a factor of 100.
Lecture 32
Last lecture:
Taylor series solution
Euler explicit method
This lecture:
Euler implicit
Euler modified
Runge Kutta method
7.2.2 Euler Implicit Method for y = f(x, y)
1 " 2
yn+1 = yn + hfn+1 - 2 𝑦n+1 h +… = yn + hfn+1 + O(h2)
y
y
y(xn+1) y(x) Run: h yn+1 y(x)
Run: h
error { error {
yn+1 Rise: hyn′ y(xn+1) Rise: hy′n+1
𝑑2 𝑓 ℎ2 ′′′
Because y"' = , the above gives a T.E.: - 𝑦n+1/2
𝑑𝑥 2 12
Example: Solve y' = -2x - y, y(0) = -1 using Euler modified method & h=0.1
= f(x, y)
xn yn 𝑦തn+1 ҧ
𝑓n+1 yexact -yn
0 -1 -0.9 0.7 𝑦തn+1 = -1 + (-2*0-(-1))* 0.1 = -0.9
0.1 -0.915 -0.8435 0.4435
f(xn+1, 𝑦തn+1) = -2*0.1-(-0.9) =0.7
0.2 -0.857075 -0.811368 0.2113675
0.3 -0.82365288 -0.801288 0.0012876 yn+1 = -1+0.1*(1+0.7)/2 =-1+0.085 = = -0.915
0.4 -0.81240585 -0.811165 -0.188835 1.45E-03
𝑦തn+1 =-0.915 + (-2*0.1-(-0.915))* 0.1 = -0.8435
where a, b, a, and b are to be determined so that the local error is as small as possible.
* Taylor series expansion for yn+1 based on ODE:
yn+1 = yn + hy′(xn, yn) + 2 𝑦n" h2 +…
1
(7)
h2 𝑑𝑓
= yn + hf(xn, yn) + ቚ +…
2 𝑑𝑥 𝑛
𝑑𝑓 𝑓 𝑓 𝑑𝑦
= 𝑥 + =f +f f
𝑑𝑥 𝑦 𝑑𝑥 x y
yn+1 = yn + hfn + h2/2 (fx + fyf )n (13)
The above are 3 equations for 4 unknowns → many possible valid choices.
yn+1 = yn + ak1 + bk2; k2 = h f(xn+ ah, yn +bk1)
2nd order Runge-Kutta Method
a + b = 1; ba = 1/2; bb = 1/2
k1 = h f(xn, yn),
yn + k1/2
k2 = h f(xn+ h/2, yn + k1/2)
& yn+1 = yn + k2 xn xn + h/2 xn+1 𝑥
Mid-point method
* Ralston’s method
Choose: a = 1/3 b = 2/3, a = b = 3/4.
0.8 0.2096 0.282253 0.252122 0.2493346 0.24932896 1.E-04 Euler modified RK4
1 0.32768 0.401878 0.37074 0.3678852 0.36787944
1.2 0.462144 0.534898 0.504007 0.5011999 0.50119421 1.E-05
1.4 0.609715 0.679082 0.649285 0.6466024 0.64659696
1.6 0.767772 0.832568 0.804414 0.8019016 0.80189652 1.E-06
1.8 0.934218 0.993807 0.96762 0.9653036 0.96529889 0 0.5 1 1.5 2 x
2 1.107374 1.161506 1.137448 1.1353395 1.13533528
Butcher’s 6th-order RK Method
1
𝑦n+1 = 𝑦𝑛 + (7𝑘1 + 32𝑘3 + 12𝑘4 + 32𝑘5 + 7𝑘6 )
90
𝑘1 = ℎ𝑓(𝑥𝑛 , 𝑦𝑛 )
1 1
𝑘2 = ℎ𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 + 𝑘1 )
4 4
1 1 1
𝑘3 = ℎ𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 + 𝑘1 + 𝑘2 )
4 8 8
1 1
𝑘4 = ℎ𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 − 𝑘2 + 𝑘3 )
2 2
3 3 9
𝑘5 = ℎ𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 + 𝑘1 + 𝑘 )
4 16 16 4
3 2 12 12 8
𝑘6 = ℎ𝑓(𝑥𝑛 + ℎ, 𝑦𝑛 − 𝑘1 + 𝑘2 + 𝑘 − 𝑘 + 𝑘 )
7 7 7 3 7 4 7 5
1.E-03
Euler Explicit Euler Implicit
1.E-04 Euler modified RK4
Butcher6
1.E-05
1.E-06
1.E-07
1.E-08
0 0.5 1 1.5 2
x
7.3.3 Automatic Runge-Kutta methods
▪ Solve each step twice, once as a full step and then as two half steps
▪ Estimate local truncation error between two predictions using 4th-order & 5th order RK methods
• Compute 6 or 7 slopes (or derivatives)
𝑘1 = ℎ𝑓(𝑥𝑛 , 𝑦𝑛 )
𝑘2 = ℎ𝑓(𝑥𝑛 + 𝟐 𝒉, 𝑦𝑛 + 21 𝑘1 )
𝑘3 = ℎ𝑓(𝑥𝑛 + 𝟑 𝒉, 𝑦𝑛 + 31 𝑘1 + 32 𝑘2 )
𝑘4 = ℎ𝑓(𝑥𝑛 + 𝟒 𝒉, 𝑦𝑛 + 41 𝑘1 + 42 𝑘2 + 43 𝑘3 )
𝑘5 = ℎ𝑓(𝑥𝑛 + 𝟓 𝒉, 𝑦𝑛 + 51 𝑘1 + 52 𝑘2 + 53 𝑘3 + 54 𝑘4 )
𝑘6 = ℎ𝑓(𝑥𝑛 + 𝟔 𝒉, 𝑦𝑛 + 61 𝑘1 + 62 𝑘2 + 63 𝑘3 + 64 𝑘4 + 65 𝑘5 )
𝑘7 = ℎ𝑓(𝑥𝑛 + 𝟕 𝒉, 𝑦𝑛 + 71 𝑘1 + 72 𝑘2 + 73 𝑘3 + 74 𝑘4 + 75 𝑘5 + 76 𝑘6 )
𝑦𝑛+1 = 𝑦𝑛 + 1 𝑘1 + 2 𝑘2 + 3 𝑘3 + 4 𝑘4 + 5 𝑘5 + 6 𝑘6 + 7 𝑘7 4th order accurate
𝑦𝑛+1 = 𝑦𝑛 + 1 𝑘1 + 2 𝑘2 + 3 𝑘3 + 4 𝑘4 + 5 𝑘5 + 6 𝑘6 + 7 𝑘7
5th order accurate
𝐸𝑟𝑟𝑜𝑟 = |𝑦𝑛+1 − 𝑦𝑛+1 | 4th order error estimate
* Note: (fn-3, fn-2, fn-1, fn) are all past values already obtained; no estimated values are used;
no additional effort is involved to get (fn-2, fn-1, fn).
* Problem: need (f1, f2, f3) besides f0 to start the process for f4.
Single step method (e.g. RK4) must be used to start.
* However, if AB4 scheme is used, one only needs to employ RK4 (standard program is available in the open literature)
to compute the first 3 points: f1, f2, & f3. One can switch to AB4 to compute f4, …, fn.
* It has the same order of accuracy but takes only 1/4 of effort.
* AB4 is NOT used alone; it is used with AM4 together
7.4.3 Adams-Moulton methods:
4-point:
ℎ 19 5 (5)
yn+1 = yn + (9fn+1 +19fn - 5fn-1+ fn-2) - h y (x)
24 720
* Predictor:
Use the 4-point Adams-Bashforth scheme
ℎ
𝑦𝑛+1 = yn + 24 (55fn - 59fn-1 + 37fn-2 -9fn-3)
ℎ
Accept: yn+1 = yn + (9fn+1 +19fn - 5fn-1+ fn-2)
24
* The above scheme is referred as 4th order Adams-Bashforth- Adams-Moulton (ABAM) scheme
ii) For h=0.2, we first compute y(0.2), y(0.4), and y(0.6) using RK4 method.
The results are listed in “y_ABAM4” column from 2nd to 4th row.
iii) At x=0.6, we switch to ABAM4 by computing the predictor
0.2
𝑦(0.8) = y(0.6) + (55*0.1790842 – 59* 0.479021 + 37*0.7644896 -9*1) =1.3754723
24
iv) Compute the slope at x=0.8 using f*(x=0.8, 1.3754723) =1-0.8*1.3754723 = -0.10038
0.2
v) Corrector : y(0.8) = y(0.6) + (9*(-0.10038) +19* 0.1790842 –5*0.479021 +0.7644896) = 1.375431273
24
vi) The rest of the results are given below.
x y_ABAM4 s1 s2 s3 s4 y_pred f *_n+1
0 1 1 0.89 0.8911 0.76436
0.2 1.177551867 0.7644896 0.6238 0.62802 0.4787376 1.E+00 1.8
0.4 1.302447455 0.479021 0.324825 0.332535 0.1786273 Error_ABAM4
0.6 1.368193082 0.1790842 0.029729 0.040184 -0.100984 1.375472 Error y 1.6
0.8 1.375431273 -0.100345 1.331752 -0.10038
1.E-01 Error_RK4
1 1.33119195 -0.3311919 1.248023 -0.33175 1.4
1.2 1.247104567 -0.4965255 1.137995 -0.49763
y_ABAM4
1.4 1.136961971 -0.5917468 1.015278 -0.59319 1.E-02 1.2
1.6 1.014363992 -0.6229824 0.891517 -0.62444
1.8 0.890888776 -0.6035998 0.775323 -0.60473 1
2 0.775046779 -0.5500936 0.671985 -0.55065 1.E-03
2.2 0.67202954 -0.478465 0.583809 -0.47837
0.8
2.4 0.584077441 -0.4017859 0.510829 -0.40114
2.6 0.511201683 -0.3291244 0.451628 -0.32815
2.8 0.452002305 -0.2656065 0.404086 -0.26456 1.E-04 0.6
3 0.40439381 -0.2131814 0.365929 -0.21226
3.2 0.366141256 -0.171652 0.335071 -0.17097 0.4
3.4 0.335189183 -0.1396432 0.309771 -0.13924 1.E-05
3.6 0.309816449 -0.1153392 0.288673 -0.11518 0.2
3.8 0.288670599 -0.0969483 0.270762 -0.09696
4 0.270734064 -0.0829363 0.255298 -0.08305
1.E-06 0
4.2 0.255261919 -0.0721001 0.241751 -0.07225
0 1 2 3 4 5 x
4.4 0.241715986 -0.0635503 0.229737 -0.0637
4.6 0.2297076 -0.056655 0.218976 -0.05679
4.8 0.218953078 -0.0509748 0.209258 -0.05108
5 0.20924143 -0.0462072 0.200423 -0.04629
vii) We can also continue with RK4 to obtain y(x). ABAM4 performs similarly in comparison with RK4.
Lecture 34
Last lecture:
Runge Kutta high order method
Automatic method
Multistep methods
This lecture:
d = lh ± 1 + 𝜆2 ℎ2
Comments: 10 0
y(t) A=100
• The stability on Dt is controlled by Ah = ADt<2~3
-1
--to catch the rapid transient at small time. 10
exact solution
* The long-time solution is dictated by 𝑒 −𝑡 /(A-1)
* RK4 (explicit method in general) is not suitable 10
-2
tan −1 ( ) + d
1 y
x=
a a
where d is the integration constant. Since y→ as x→b= a2, we have
1 1
a2 = +d d = a2 −
a2 a2
Thus near the singularity, x=b, the solution has the following
asymptotic behavior:
y = a tan[a( x − d )] = a tan[ax − a 3 + ]
2
i.e. y ~ b / tan[ b (b − x)] (asymptotic solution) (5)
1.E+01
1.E+00
0.0 0.2 0.4 0.6 0.8 1.0
1.E+10
y
1.E+09
1.E+08
1.E+07
RKF6 asymp
1.E+06
1.E+05
1.E+04
1.E+03
x=b
1.E+02
1.E+01 x
0.85 0.86 0.87 0.88 0.89 0.90 0.91 0.92 0.93 0.94
Excel formula:
x corrector predictor
0 1 1
=h+B2 =0.5*(C2+D3+h*(D3^2+B3)) =C2+h*(C2^2+B2)
=h+B3 =0.5*(C3+D4+h*(D4^2+B4)) =C3+h*(C3^2+B3)
=h+B4 =0.5*(C4+D5+h*(D5^2+B5)) =C4+h*(C4^2+B4)
=h+B5 =0.5*(C5+D6+h*(D6^2+B6)) =C5+h*(C5^2+B5)
* Excel formula:
x y s1 s2 s3 s4
=B2+h/2+ =B2+h/2+ =B2+h+(C2
0 1 =(B2+C2^2) (C2+h*D2/2)^2 (C2+h*E2/2)^2 +h*F2)^2
=C2+h/6*(D2+ =B3+h/2+ =B3+h/2+ =B3+h+(C3
=h+B2 2*E2+2*F2+G2) =(B3+C3^2) (C3+h*D3/2)^2 (C3+h*E3/2)^2 +h*F3)^2
=C3+h/6*(D3+ =B4+h/2+ =B4+h/2+ =B4+h+(C4
=h+B3 2*E3+2*F3+G3) =(B4+C4^2) (C4+h*D4/2)^2 (C4+h*E4/2)^2 +h*F4)^2
=C4+h/6*(D4+ =B5+h/2+ =B5+h/2+ =B5+h+(C5
=h+B4 2*E4+2*F4+G4) =(B5+C5^2) (C5+h*D5/2)^2 (C5+h*E5/2)^2 +h*F5)^2