Beruflich Dokumente
Kultur Dokumente
Optimization
Runge-Kutta Method
By
Assist Prof. Dr. Ahmed Jabbar
Runge-Kutta 2nd Order Method
dy
For f ( x, y ), y (0) y0
dx
yi 1 yi a1k1 a2 k 2 h
where
resulting in
yi 1 yi k2h
where
1 1
𝑘1 = 𝑓 𝑥𝑖 , 𝑦𝑖 𝑘2 = 𝑓 𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ
2 2
Ralston’s Method
2
Here 𝑎2 = is chosen, giving
3
1 3 3
a1 p1 q11
3 4 4
resulting in
1 2
𝑦𝑖+1 = 𝑦𝑖 + 𝑘1 + 𝑘2 ℎ
3 3
where 3 3
𝑘1 = 𝑓 𝑥𝑖 , 𝑦𝑖 𝑘2 = 𝑓 𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ
4 4
How to write Ordinary Differential Equation
How does one write a first order differential equation in the form of
𝑑𝑦
= 𝑓 𝑥, 𝑦
𝑑𝑥
Example
𝑑𝑦
+ 2𝑦 = 1.3𝑒 −𝑥 , 𝑦 0 = 5
𝑑𝑥
is rewritten as 𝑑𝑦
= 1.3𝑒 −𝑥 − 2𝑦, 𝑦 0 = 5
𝑑𝑥
In this case
𝑓 𝑥, 𝑦 = 1.3𝑒 −𝑥 − 2𝑦
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
𝑑𝜃
= −2.2067 × 10−12 𝜃 4 − 81 × 108 , 𝜃 0 = 1200𝐾
𝑑𝑡
Find the temperature at t 480 seconds using Heun’s method. Assume a step size of
h 240 seconds.
𝑑𝜃
= −2.2067 × 10−12 𝜃 4 − 81 × 108
𝑑𝑡
f t , 2.2067 10 12 4 81108
1 1
𝜃𝑖+1 = 𝜃𝑖 + 𝑘1 + 𝑘2 ℎ
2 2
Solution
Step 1:
𝑖 = 0, 𝑡0 = 0, 𝜃0 = 𝜃(0) = 1200𝐾
𝑘1 = 𝑓 𝑡0 , 𝜃𝑜 𝑘2 = 𝑓 𝑡0 + ℎ, 𝜃0 + 𝑘1 ℎ
= 𝑓 0,1200 = 𝑓 0 + 240,1200 + −4.5579 240
= −2.2067 = 𝑓 240,106.09
× 10−12 12004 − 81 × 108 = −2.2067 × 10−12 (106.094 − 81
= −4.5579 = 0.017595
1 1
𝜃1 = 𝜃0 + 𝑘 + 𝑘 ℎ
2 1 2 2
1 1
= 1200 + −4.5579 + 0.017595 240
2 2
= 1200 + −2.2702 240
= 655.16𝐾
Solution Cont
Step 2:
𝑖 = 1, 𝑡1 = 𝑡0 + ℎ = 0 + 240 = 240, 𝜃1 = 655.16𝐾
𝑘1 = 𝑓 𝑡1 , 𝜃1 𝑘2 = 𝑓 𝑡1 + ℎ, 𝜃1 + 𝑘1 ℎ
= 𝑓 240,655.16 = 𝑓 (240 + 240,655.16
= −2.2067 = 𝑓 480,561.87
× 10−12 655.164 − 81 × 108 = −2.2067 × 10−12 (561.874 − 81
= −0.20206
= −0.38869
1 1
𝜃2 = 𝜃1 + 𝑘1 + 𝑘2 ℎ
2 2
1 1
= 655.16 + −0.38869 + −0.20206 240
2 2
= 655.16 + −0.29538 240
= 584.27𝐾
Solution Cont
The exact solution of the ordinary differential equation is given by the
solution of a non-linear equation as
𝜃 − 300
0.92593 ln − 1.8519 tan−1 0.0033333𝜃 = −0.22067 × 10−3 𝑡 − 2.9282
𝜃 + 300
(480) 647.57 K
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)
600
400
200
0
0 100 200 300 400 500
-200 Step size, h
-400
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.