Professional Documents
Culture Documents
Runge-Kutta 4th Order Method For Ordinary Differential Equations
Runge-Kutta 4th Order Method For Ordinary Differential Equations
04
Runge-Kutta 4th Order Method for
Ordinary Differential Equations
in
08.04.1
dy
+ 2 y = 1.3e x , y (0 ) = 5
dx
dy
= f ( x, y ), y (0) = y 0 form.
dx
08.04.2
Chapter 08.04
Solution
dy
+ 2 y = 1.3e x , y (0 ) = 5
dx
dy
= 1.3e x 2 y, y (0 ) = 5
dx
In this case
f ( x, y ) = 1.3e x 2 y
Example 2
Rewrite
ey
in
dy
+ x 2 y 2 = 2 sin(3 x), y (0 ) = 5
dx
dy
= f ( x, y ), y (0) = y 0 form.
dx
Solution
dy
+ x 2 y 2 = 2 sin(3 x), y (0 ) = 5
dx
dy 2 sin(3 x) x 2 y 2
=
, y (0 ) = 5
dx
ey
In this case
2 sin(3 x) x 2 y 2
f ( x, y ) =
ey
The Runge-Kutta 4th order method is based on the following
yi +1 = yi + (a1k1 + a2 k 2 + a3 k 3 + a4 k 4 )h
where knowing the value of y = y i at xi , we can find the value of y = yi +1 at xi +1 , and
ey
h = xi +1 xi
Equation (1) is equated to the first five terms of Taylor series
3
dy
1 d2y
1 d3y
2
(
)
(
)
(xi +1 xi )
yi +1 = yi +
x
x
x
x
+
xi , yi
i +1
i
i +1
i
2 xi , yi
3 xi , yi
dx
2! dx
3! dx
4
1d y
(xi +1 xi )4
+
4 xi , yi
4! dx
dy
Knowing that
= f ( x, y ) and xi +1 xi = h
dx
1
1
1
y i +1 = y i + f ( xi , y i )h + f ' ( xi , y i )h 2 + f '' ( xi , y i )h 3 + f ''' ( xi , y i )h 4
2!
3!
4!
Based on equating Equation (2) and Equation (3), one of the popular solutions used is
1
y i +1 = y i + (k1 + 2k 2 + 2k 3 + k 4 )h
6
(1)
(2)
(3)
(4)
08.04.3
k1 = f ( x i , y i )
(5a)
1
1
k2 = f xi + h, yi + k1h
2
2
(5b)
1
1
k 3 = f xi + h, y i + k 2 h
2
2
k 4 = f ( x i + h, y i + k 3 h )
(5c)
(5d)
Example 3
A ball at 1200 K is allowed to cool down in air at an ambient temperature of 300 K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
= 2.2067 10 12 ( 4 81108 ), (0 ) = 1200 K
dt
where is in K and t in seconds. Find the temperature at t = 480 seconds using RungeKutta 4th order method. Assume a step size of h = 240 seconds.
Solution
d
= 2.2067 10 12 4 81 10 8
dt
f (t , ) = 2.2067 10 12 4 81 10 8
1
i +1 = i + (k1 + 2k 2 + 2k 3 + k 4 )h
6
For i = 0 , t 0 = 0 , 0 = 1200K
k1 = f (t0 , 0 )
= f (0,1200 )
= 2.2067 10 12 (1200 4 81 10 8 )
= 4.5579
1
1
k 2 = f t0 + h, 0 + k1h
2
2
1
1
= f (120,653.05)
= 2.2067 10 12 (653.05 4 81 10 8 )
= 0.38347
1
1
k 3 = f t 0 + h, 0 + k 2 h
2
2
1
1
= f (120,1154.0 )
08.04.4
Chapter 08.04
k 2 = f t1 + h, 1 + k1h
2
2
1
1
= f (360,622.61)
= 2.2067 1012 622.614 81 108
= 0.31372
1
1
k3 = f t1 + h, 1 + k 2 h
2
2
1
1
= f (360,638.00 )
= 2.2067 10 12 638.00 4 81 10 8
08.04.5
= 0.34775
k 4 = f (t1 + h, 1 + k3 h )
= f (240 + 240,675.65 + ( 0.34775) 240)
= f (480,592.19)
= 2.2067 10 12 (592.19 4 81 10 8 )
= 0.25351
1
2 = 1 + ( k1 + 2 k 2 + 2 k 3 + k 4 ) h
6
1
= 675.65 + ( 0.44199 + 2( 0.31372 ) + 2( 0.34775) + ( 0.25351)) 240
6
1
= 675.65 + ( 2.0184 ) 240
6
= 594.91 K
2 is the approximate temperature at
t = t2
= t1 + h
= 240 + 240
= 480
2 = (480)
594.91 K
Figure 1 compares the exact solution with the numerical solution using the Runge-Kutta 4th
order method with different step sizes.
Temperature, (K)
1600
1200
h=120
800
Exact
h=240
400
h=480
0
0
200
400
600
-400
Time,t(sec)
08.04.6
Chapter 08.04
Table 1 and Figure 2 show the effect of step size on the value of the calculated temperature at
t = 480 seconds.
Table 1 Value of temperature at time, t = 480 s for different step sizes
Step size, h
480
240
120
60
30
(480)
Et
-90.278 737.85
594.91 52.660
646.16 1.4122
647.54 0.033626
647.57 0.00086900
| t | %
113.94
8.1319
0.21807
0.0051926
0.00013419
Temperature, (480)
800
600
400
200
0
0
100
200
300
400
500
-200
Step size, h
k 2 = f xi + h, yi + hk1
3
3
2
1
k 3 = f xi + h, yi hk1 + hk 2
3
3
k 4 = f (xi + h, y i + hk1 hk 2 + hk 3 )
(7b)
(7c)
(7d)
08.04.7
This formula is the same as the Simpsons 3/8 rule, if f ( x, y ) is only a function of x .
Temperature, (K)
1400
1200
4th order
1000
800
Exact
600
Heun
400
Euler
200
0
100
200
300
400
500
Time, t(sec)
Figure 3 Comparison of Runge-Kutta methods of 1st (Euler), 2nd, and 4th order.