80 Sanyasiraju V S S Yedida sryedida@[Link].
in
8.6 Runge-Kutta Methods
Runge-Kutta methods have the high-order local truncation error of the Taylor methods but
eliminate the need to compute and evaluate the derivatives of f (t, x).
8.6.1 Taylor series of a function with two variables
Suppose that f (t, x) and all its partial derivatives of order less than or equal to n + 1 are
continuous on D = {(t, x) ∣ a ≤ t ≤ b, c ≤ x ≤ d}, and let (t0 , x0 ) ∈ D. For every (t, x) ∈ D,
there exists ξ between t and t0 and µ between x and x0 with
f (t, x) = Pn (t, x) + Rn (t, x), where (8.11)
∂f ∂f
Pn (t, x) = f (t0 , x0 ) + ((t − t0 ) + (x − x0 ) )
∂t ∂x
(t − t0 )2 ∂ 2 f ∂ 2f (x − x0 )2 ∂ 2 f
+ ( + (t − t0 )(x − x 0 ) + )+⋯+
2 ∂t2 ∂t ∂x 2 ∂x2
1 n n ∂ nf
+ ∑ ( ) (t − t0 )n−j (x − x0 )j n−j j
n! j=0 j ∂t ∂x
(n+1)
1 n+1 ∂ nf
Rn (t, x) = ∑ ( ) (t − t0 )n−j+1 (x − x0 )j n+1−j j (ξ, µ)
(n + 1)! j=0 j ∂t ∂x
8.6.2 Runge-Kutta method of order two
We have x(t + ∆t) = x(t) + ∆tx′ (t) + ∆t2 x(2) (t) + ∆t (3) (t) + ⋯ From the differential equation,
2 3
3! x
we have
x′ (t) = f (t, x)
x(2) (t) = ft + fx x′ = ft + fx f
x(3) (t) = ftt + ftx f + (ft + fx f )fx + f (fxt + fxx f )
..
.
Here subscripts denote partial derivatives, and the chain rule of differentiation is used re-
peatedly. Using these derivatives of x, the Taylor series can be can be written as
∆t2
x(t + ∆t) = x + ∆t f + (ft + f fx ) + O(∆t3 )
2
∆t ∆t
= x+ f + (f + ∆t ft + ∆t f fx ) + O(∆t3 )
2 2
∆t ∆t
= x+ f + (f (t + ∆t, x + ∆tf ) + O(∆t2 )) + O(∆t3 )
2 2
∆t ∆t
= x+ f + (f (t + ∆t, x + ∆tf )) + O(∆t3 )
2 2
Lecture Notes MA5470 Numerical Analysis 81
which is equivalent to
1
x(t + ∆t) = x(t) + (K1 + K2 ) where (8.12)
2
K1 = ∆t f (t, x)
K2 = ∆t f (t + ∆t, x + K1 )
Formula (8.16) is the second-order Runge-Kutta method. It is also known as Heun’s
method. In general, second-order Runge-Kutta formulas are of the form
x(t + ∆t) = x + w1 ∆tf + w2 ∆tf (t + α∆t, x + β∆tf ) + O(∆t3 ) (8.13)
= x + w1 ∆tf + w2 ∆t (f + α∆tft + β∆tf fx )) + O(∆t3 ) (8.14)
where w1 , w2 , α, and β are parameters at our disposal. Comparing (8.13) with the Taylor
series in two variables (8.11) gives
1 1
w1 + w2 = 1, w2 α = , w2 β = (8.15)
2 2
One solution is w1 = w2 = 21 , α = β = 1, which is the Heun’s method. Another solution is
w1 = 0, w2 = 1, α = β = 12 . This is the modified Euler method given by
x(t + ∆t) = x(t) + K2 where (8.16)
∆t K1
K1 = ∆t f (t, x), K2 = ∆t f (t + ,x + )
2 2
There are infinitely many solutions to (8.15) but every such solution is only second order
accurate, therefore, as far as the accuracy is concerned, any solution can be used.
A generalized R-stage Runge-Kutta method can be written as
R
xi+1 = xi + ∆t ∑ wj Kj (8.17)
j=1
K1 = f (t, x)
j−1 j−1
Kj = f (t + ∆taj , x + ∆t ∑ bjk Kk ) , aj = ∑ bjk , j = 2, 3, ⋯, R
k=1 k=1
The summation in the (8.17) is nothing but the weighted average of the function values of
f . Also notice that any Kj involves only up to Kj−1 only, therefore, the general RK method
given by (8.17) are explicit in nature. The general scheme is also can be written as
R
xi+1 = xi + ∑ wj Kj (8.18)
j=1
K1 = ∆t f (t, x)
j−1 j−1
Kj = ∆t f (t + ∆taj , x + ∑ bjk Kk ) , aj = ∑ bjk , j = 2, 3, ⋯, R
k=1 k=1
82 Sanyasiraju V S S Yedida sryedida@[Link]
8.6.3 3-Stage Runge-Kutta method
1 1 1
w1 + w2 + w3 = 1, w2 a2 + w3 a3 = , w2 a22 + w3 a23 = , w3 a2 b32 = (8.19)
2 3 6
One 3-stage RK-method satisfying (8.19) is w1 = 41 , w2 = 0, w3 = 34 , a2 = 31 , a3 = 23 , b23 = 23 .
The corresponding scheme is
1
xi+1 = xi + (K1 + 3K3 ) where (8.20)
4
K1 = ∆t f (ti , xi ),
∆t K1
K2 = ∆t f (ti + , x+ )
3 3
2∆t 2K2
K3 = ∆t f (ti + , x+ )
3 3
8.6.4 4-Stage Runge-Kutta method
A very popular 4-stage RK-method satisfying (8.19) is w1 = w4 = 16 , w2 = w3 = 13 , a2 = a3 = 12 ,
a4 = 1, b21 = b32 = 23 and b43 = 1. The corresponding scheme is
1
xi+1 = xi + (K1 + 2K2 + 2K3 + K4 ) where (8.21)
6
K1 = ∆t f (ti , xi ),
∆t K1
K2 = ∆t f (ti + , x+ )
2 2
∆t K2
K3 = ∆t f (ti + , x+ )
2 2
K4 = ∆t f (ti + ∆t, x + K3 )
8.6.5 Stage Vs Order for Runge-Kutta methods
Stage 2 3 4 5 6 7 8
Order 2 3 4 4 5 5 6
8.6.6 Numerical Illustration
1. Compute the numerical solution of x′ = x − t2 + 1 in the interval 0 ≤ t ≤ 2 with the initial
condition x(0) = 0.5 using Second order Runge-Kutta method and also using Modified
Euler method with step length ∆t = 0.2.
Lecture Notes MA5470 Numerical Analysis 83
Solution : Given fi = xi − t2i + 1, start with t = 0 and step length ∆t = 0.2
Heun’s method : K1 = ∆t f (ti , xi )), K2 = ∆t f (ti +∆t, xi +K1 ) and xi+1 = xi + K1 +K
2
2
.
K1 = ∆t(x0 − t20 + 1) = 0.2(.5 − 02 + 1) = 0.3000
K2 = ∆t((x0 + K1 ) − (t0 + ∆t)2 + 1) = 0.2(.8 − 0.22 + 1) = 0.3520
x1 = x0 + .5(K1 + K2 ) = .5 + .2(.3 + .352) = .8260
K1 = ∆t(x1 − t21 + 1) = 0.2(.8260 − 0.22 + 1) = 0.3572
K2 = ∆t((x1 + K1 ) − (t1 + ∆t)2 + 1) = 0.2(.8260 + 0.3572 − 0.42 + 1) = 0.4046
x2 = x1 + .5(K1 + K2 ) = .8260 + .2(0.3572 + 0.4046) = 1.2069
K1 = ∆t(x2 − t22 + 1) = 0.2(1.2069 − 0.42 + 1) = 0.4094
K2 = ∆t((x2 + K1 ) − (t2 + ∆t)2 + 1) = 0.2(1.2069 + 0.4094 − 0.62 + 1) = 0.4513
x3 = x2 + .5(K1 + K2 ) = 1.2069 + .2(0.4094 + 0.4513) = 1.6372
x4 = x3 + .5(K1 + K2 ) = 1.6372 + .2(0.4554 + 0.4905) = 2.1102
x5 = x4 + .5(K1 + K2 ) = 2.1102 + .2(0.4940 + 0.5209) = 2.6177
x6 = x5 + .5(K1 + K2 ) = 2.6177 + .2(0.5235 + 0.5402) = 3.1496
x7 = x6 + .5(K1 + K2 ) = 3.1496 + .2(0.5419 + 0.5463) = 3.6937
x8 = x7 + .5(K1 + K2 ) = 3.6937 + .2(0.5467 + 0.5361) = 4.2351
x9 = x8 + .5(K1 + K2 ) = 4.2351 + .2(0.5350 + 0.5060) = 4.7556
x10 = x9 + .5(K1 + K2 ) = 4.7556 + .2(0.5031 + 0.4517) = 5.2331
Modified Euler method : K1 = ∆t f (ti , xi )), K2 = ∆t f (ti + ∆t
2 , xi + 2 )
K1
and
xi+1 = xi + K2 .
K1 = ∆t(x0 − t20 + 1) = 0.2(.5 − 02 + 1) = 0.3000
K2 = ∆t((x0 + K1 /2) − (t0 + ∆t/2)2 + 1) = 0.2(.5 + .3/2 − (0 + 0.2/2)2 + 1) = 0.3280
x1 = x0 + K2 = .5 + .3280 = 0.8280
K1 = ∆t(x1 − t21 + 1) = 0.2(0.8280 − .22 + 1) = 0.3576
K2 = ∆t((x1 + K1 /2) − (t1 + ∆t/2)2 + 1) = 0.2(0.8280 + .3/2 − (.2 + 0.2/2)2 + 1) = 0.3834
x2 = x1 + K2 = 0.8280 + 0.3834 = 1.2114
x3 = 1.6447, x4 = 2.1213, x5 = 2.6332, x6 = 3.1705
x7 = 3.7212, x8 = 4.2706, x9 = 4.8010, x10 = 5.2904
Exact Solution
x1 = 0.8292, x2 = 1.2141, x3 = 1.6489, x4 = 2.1272, x5 = 2.6408
x6 = 3.1799, x7 = 3.7324, x8 = 4.2835, x9 = 4.8152, x10 = 5.3054
84 Sanyasiraju V S S Yedida sryedida@[Link]
2. Use the Runge-Kutta method of order four with ∆t = 0.2, to obtain the numerical
solution of the initial-value problem x′ = xt2 + 1, in the interval 0 ≤ t ≤ 2, x(0) = 0.5.
Solution :
x0 =
0.5
K1 =
0.2 ∗ f (0, 0.5) = 0.2(1.5) = 0.3
K2 =
0.2f (0.1, 0.65) = 0.328
K3 =
0.2f (0.1, 0.664) = 0.3308
K4 =
0.2f (0.2, 0.8308) = 0.35816
1
x1 = 0.5 + (0.3 + 2(0.328) + 2(0.3308) + 0.35816) = 0.8292933
6
The comparison of the numerical and exact solutions along with error is given in the
following Table.
ti Exact RK - 4 Error
0.0 0.5000000 0.5000000 0
0.2 0.8292986 0.8292933 0.0000053
0.4 1.2140877 1.2140762 0.0000114
0.6 1.6489406 1.6489220 0.0000186
0.8 2.1272295 2.1272027 0.0000269
1.0 2.6408591 2.6408227 0.0000364
1.2 3.1799415 3.1798942 0.0000474
1.4 3.7324000 3.7323401 0.0000599
1.6 4.2834838 4.2834095 0.0000743
1.8 4.8151763 4.8150857 0.0000906
2.0 5.3054720 5.3053630 0.0001089
3. Compare the solutions of Euler (with step length ∆t = 0.025), Modified Euler (with
step length ∆t = 0.05) and RK-4 (with step length ∆t = 0.1) solutions of x′ = xt2 + 1,
in the interval 0 ≤ t ≤ .5, x(0) = 0.5.
ti Exact Euler Modified Euler RK-4
0.0 0.5000000 0.5000000 0.5000000 0.5000000
0.1 0.6574145 0.6554982 0.6573085 0.6574144
0.2 0.8292986 0.8253385 0.8290778 0.8292983
0.3 1.0150706 1.0089334 1.0147254 1.0150701
0.4 1.2140877 1.2056345 1.2136079 1.2140869
0.5 1.4256394 1.4147264 1.4250141 1.4256384
8.6.7 Problems
1. Use the Modified Euler method to approximate the solutions to each of the following
IVPs, and compare the results to the actual values.
Lecture Notes MA5470 Numerical Analysis 85
(a) x′ = te3t − 2x, 0 ≤ t ≤ 1, x(0) = 0, with ∆t = 0.5; actual solution x(t) = 15 te3t −
−2t .
25 e + 25 e + e
1 3t 1 3t
(b) x′ = 1 + (t − x)2 , 2 ≤ t ≤ 3, x(2) = 1, with ∆t = 0.5; actual solution x(t) = t + 1−t
1
.
(c) x′ = 1 + xt , 1 ≤ t ≤ 2, x(1) = 2, with ∆t = 0.25; actual solution y(t) = t ln(t) + 2t.
(d) x′ = cos 2t + sin 3t, 0 ≤ t ≤ 1, x(0) = 1, with ∆t = 0.25; actual solution x(t) =
2 sin 2t − 3 cos 3t + 3 .
1 1 4
2. Prove that when the fourth-order Runge-Kutta method is applied to the problem
x′ = λx, the formula for advancing this solution is
hλ h2 λ2 h4 λ4
x(t + h) = (1 + + ++ ) x(t)
2 6 24
3. Use the Runge-Kutta method of order four to approximate the solutions to each of the
following initial-value problems, and compare the results to the actual values.
(a) x′ = 2−2tx
t2 +1 , 0 ≤ t ≤ 1, x(0) = 1, ∆t = 0.2; Exact solution x(t) = 2t+1
t2 +1 .
−1
(b) x′ = x2
t+1 , 0 ≤ t ≤ 2, x(1) = − ln2
1
, ∆t = 0.25; Exact solution x(t) = ln(1+t) .
x2 +x
(c) x′ = t , 0 ≤ t ≤ 3, x(0) = −2, ∆t = 0.5; Exact solution x(t) = 2t
1−2t .
√
(d) x′ = −tx + 4t
x , 0 ≤ t ≤ 1, x(0) = 1, ∆t = 0.2; Exact solution x(t) = 4 − 3e−t .