Professional Documents
Culture Documents
Runge-Kutta 2 Order Method: y y y X F DX Dy
Runge-Kutta 2 Order Method: y y y X F DX Dy
dy
For f ( x, y ), y (0) y0
dx
yi 1 yi a1k1 a2 k 2 h
where
k1 f xi , yi
k2 f xi p1h, yi q11k1h
2 http://numericalmethods.eng.usf.edu
Heun’s Method
Heun’s method
y
Slope f xi h, yi k1h
Here a2=1/2 is chosen
1 yi+1, predicted
a1
2 Slope f xi , yi
p1 1
q11 1 Average Slope
1
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 , yi
k 2 f xi h, yi k1h
3 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 k2h
where
k1 f xi , yi
1 1
k 2 f x i h , y i k1 h
2 2
4 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 x i h , y i k1 h
4 4
5 http://numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of
f x, y
dy
dx
Example
2 y 1.3e x , y0 5
dy
dx
is rewritten as
1.3e x 2 y, y0 5
dy
dx
In this case
f x, y 1.3e x 2 y
6 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
dt
2.2067 10 12 4 81108 , 0 1200K
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
7 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
655.16 0.38869 0.20206240
1
2 2
655.16 0.29538240
584.27 K
9 http://numericalmethods.eng.usf.edu
Solution Cont
300
0.92593 ln 1.8519 tan 1 0.0033333 0.22067 103 t 2.9282
300
(480) 647.57 K
10 http://numericalmethods.eng.usf.edu
Comparison with exact results
1200
h=120
Temperature, θ(K)
Exact
800
h=240
400
h=480
0
0 100 200 300 400 500
-400
Time, t(sec)
11 http://numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h
12 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
13 http://numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta 2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta methods
14 http://numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta 2nd Order Methods
Step size, t %
h
Euler Heun Midpoint Ralston
480 252.54 160.82 86.612 30.544
240 82.964 9.7756 50.851 6.5537
120 15.566 0.58313 6.5823 3.1092
60 5.0352 0.36145 1.1239 0.72299
30 2.2864 0.097625 0.22353 0.15940
1100
Temperature, θ(K)
1000 Midpoint
900 Ralston
800 Heun
700
Analytical
600
Euler
500
0 100 200 300 400 500 600
Time, t (sec)
Figure 4. Comparison of Euler and Runge Kutta 2nd order methods with
exact results.
16 http://numericalmethods.eng.usf.edu
Runge-Kutta 4th Order Method
For dy
f ( x, y ), y (0) y0
dx
Runge Kutta 4th order method is given by
k4 f xi h, yi k3h
2 http://numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of
f x, y
dy
dx
Example
2 y 1.3e x , y0 5
dy
dx
is rewritten as
1.3e x 2 y, y0 5
dy
dx
In this case
f x, y 1.3e x 2 y
3 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
dt
2.2067 10 12 4 81108 , 0 1200K
Find the temperature at t 480 seconds using Runge-Kutta 4th order method.
k1 f t0 , o f 0,1200 2.2067 1012 12004 81108 4.5579
k 2 f t0 h, 0 k1h f 0 240,1200 4.5579240
1 1 1 1
2 2 2 2
f 120,653.05 2.2067 1012 653.054 81108 0.38347
k3 f t0 h, 0 k 2 h f 0 240,1200 0.38347240
1 1 1 1
2 2 2 2
f 120,1154.0 2.2067 1012 1154.0 4 81108 3.8954
t t1 t0 h 0 240 240
240 1 675.65K
6 http://numericalmethods.eng.usf.edu
Solution Cont
Step 2: i 1, t1 240,1 675.65K
k1 f t1 ,1 f 240,675.65 2.2067 1012 675.654 81108 0.44199
k 2 f t1 h,1 k1h f 240 240, 675.65 0.44199240
1 1 1 1
2 2 2 2
f 360,622.61 2.2067 1012 622.614 81108 0.31372
k3 f t1 h,1 k 2 h f 240 240,675.65 0.31372240
1 1 1 1
2 2 2 2
f 360, 638.00 2.2067 1012 638.004 81108 0.34775
7 http://numericalmethods.eng.usf.edu
Solution Cont
1
2 1 k1 2k2 2k3 k4 h
6
675.65 0.44199 2 0.31372 2 0.34775 0.25351240
1
6
675.65 2.0184240
1
6
594.91K
2 is the approximate temperature at
480 2 594.91K
8 http://numericalmethods.eng.usf.edu
Solution Cont
(480) 647.57 K
9 http://numericalmethods.eng.usf.edu
Comparison with exact results
1600
Temperature, θ(K)
1200
h=120
800 Exact
h=240
400
h=480
0
0 200 400 600
-400
Time,t(sec)
600
400
200
0
0 100 200 300 400 500
-200
Step size, h
12 http://numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta Methods
1400
Temperature, θ(K)
1200
4th order
1000
800
Exact
600
Heun
400
200 Euler
0
0 100 200 300 400 500
Time, t(sec)