Lecture 7 Runge-Kutta 2nd Order Method
Lecture 7 Runge-Kutta 2nd Order Method
http://numericalmethods.eng.usf.e
du
Transforming Numerical Methods Education for STEM
Undergraduates
http://
12/25/24 numericalmethods.eng.usf.edu 1
Runge-Kutta 2nd Order
Method
http://numericalmethods.eng.usf.
edu
Runge-Kutta 2nd Order
Method
dy
For f ( x, y ), y (0) y0
dx
yi 1 yi a1k1 a 2 k 2 h
where
k1 f xi , yi
k2 f xi p1h, yi q11k1h
3 http://numericalmethods.eng.usf.edu
Heun’s Method
Heun’s method
y
Slope f xi h, yi k1h
Here a2=1/2 is
1 yi+1, predicted
a chosen
1
2 Slope f xi , yi
p1 1
1
q11 1 Average Slope f xi h, yi k1h f xi , yi
2
yi
resulting in
1 1
yi 1 yi k1 k2 h
2 2 xi xi+1
x
where
Figure 1 Runge-Kutta 2nd order method (Heun’s method)
k1 f xi , y i
k 2 f xi h, y i k1 h
4 http://numericalmethods.eng.usf.edu
Midpoint Method
Here a2 1 is chosen, giving
a1 0
1
p1
2
1
q11
2
resulting in
yi 1 yi k2 h
where
k1 f xi , yi
1 1
k 2 f x i h , y i k1 h
2 2
5 http://numericalmethods.eng.usf.edu
Ralston’s Method
Here a2 2 is chosen, giving
3
1
a1
3
3
p1
4
3
q11
4
resulting in
1 2
yi 1 yi k1 k 2 h
3 3
where
k1 f xi , yi
3 3
k 2 f xi h, yi k1h
4 4
6 http://numericalmethods.eng.usf.edu
How to write Ordinary
Differential Equation
How does one write a first order differential equation in the form of
dy
f x, y
dx
Example
dy
2 y 1.3e x , y 0 5
dx
is rewritten as
dy
1.3e x 2 y, y 0 5
dx
In this case
f x, y 1.3e x 2 y
7 http://numericalmethods.eng.usf.edu
Example
A ball at 1200K is allowed to cool down in air at an ambient temperature
of 300K. 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 8110 8 , 0 1200 K
dt
Find the temperature at t 480 seconds using Heun’s method. Assume a step size of
h 240 seconds.
d
dt
2.2067 10 12 4 81108
f t , 2.2067 10 12 4 81108
1 1
i 1 i k1 k 2 h
2 2
8 http://numericalmethods.eng.usf.edu
Solution
Step 1: i 0, t0 0, 0 (0) 1200K
1 1
2 1 k1 k 2 h
2 2
1 1
655.16 0.38869 0.20206 240
2 2
655.16 0.29538240
584.27 K
10 http://numericalmethods.eng.usf.edu
Solution Cont
(480) 647.57 K
11 http://numericalmethods.eng.usf.edu
Comparison with exact
results
1200
Exact h=120
Temperature, θ(K)
800
h=240
400
h=480
0
0 100 200 300 400 500
-400
Time, t(sec)
12 http://numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h
13 http://numericalmethods.eng.usf.edu
Effects of step size on Heun’s
Method
800
Temperature, θ(480)
600
400
200
0
0 100 200 300 400 500
-200 Step size, h
-400
14 http://numericalmethods.eng.usf.edu
Comparison of Euler and
Runge-Kutta 2nd Order
Methods
Table 2. Comparison of Euler and the Runge-Kutta methods
(480)
Step size,
h Euler Heun Midpoint Ralston
15 http://numericalmethods.eng.usf.edu
Comparison of Euler and
Runge-Kutta 2nd Order
Methods
t %
Step size,
h
Euler Heun Midpoint Ralston
1100
θ(K)
1000 Midpoint
Temperature,
900 Ralston
800 Heun
700
Analytical
600
Euler
500
0 100 200 300 400 500 600
Time, t (sec)
http://numericalmethods.eng.usf.edu/topics/
runge_kutta_2nd_method.html
THE END
http://numericalmethods.eng.usf.edu