Professional Documents
Culture Documents
Unit-5 - R-K Method
Unit-5 - R-K Method
• The method is well suited for commuters because it needs no special starting
procedure, makes light demand on storage, and repeatedly uses the same
straightforward computational procedure.
We will mainly use 2nd and 4th order R-K method.
For 𝑛 = 1,
1
𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + (𝐾1 + 𝐾2 )
2
Here 𝐾1 = 0.1 𝑓(𝑥0 , 𝑦0 ) = 0.1 𝑓(0,2)
= 0.1 (2 − 0) = 0.2
And 𝐾2 = 0.1 𝑓(𝑥0 + ℎ, 𝑦0 + 𝐾1 ) = 0.1 𝑓(0.1, 2 + 0.2)
= 0.1 𝑓(0.1,2.2)
= 0.1 (2.2 − 0.1)
= 0.21
Therefore,
1
𝑦1 = 𝑦(0.1) = 2 + (0.2 + 0.21)
2
∴ 𝑦1 = 2.205
For 𝑛 = 2,
1
𝑦2 = 𝑦(𝑥2 ) = 𝑦1 + (𝐾1 + 𝐾2 )
2
Here 𝐾1 = 0.1 𝑓(𝑥1 , 𝑦1 ) = 0.1 𝑓(0.1,2.205)
= 0.1 (2.205 − 0.1) = 0.2105
And 𝐾2 = 0.1 𝑓(𝑥1 + ℎ, 𝑦1 + 𝐾2 ) = 0.1 𝑓(0.2, 2.205 + 0.2105)
= 0.1 𝑓(0.2,2.4155)
= 0.1 (2.4155 − 0.2)
= 0.2216
Therefore,
1
𝑦2 = 𝑦(0.2) = 2.205 + (0.2105 + 0.2216)
2
∴ 𝑦2 = 2.4211
For 𝑛 = 3,
1
𝑦3 = 𝑦(𝑥3 ) = 𝑦2 + (𝐾1 + 𝐾2 )
2
Here 𝐾1 = 0.1 𝑓(𝑥2 , 𝑦2 ) = 0.1 𝑓(0.2,2.4211)
= 0.1 (2.4211 − 0.2) = 0.2221
And 𝐾2 = 0.1 𝑓(𝑥2 + ℎ, 𝑦2 + 𝐾1 ) = 0.1 𝑓(0.3, 2.4211 + 0.2221)
= 0.1 𝑓(0.3,2.6432)
= 0.1 (2.6432 − 0.3)
= 0.2343
Therefore,
1
𝑦3 = 𝑦(0.3) = 2.4211 + (0.2221 + 0.2343)
2
∴ 𝑦3 = 2.6493
For 𝑛 = 4,
1
𝑦4 = 𝑦(𝑥4 ) = 𝑦3 + (𝐾1 + 𝐾2 )
2
Here 𝐾1 = 0.1 𝑓(𝑥3 , 𝑦3 ) = 0.1 𝑓(0.3,2.6493)
= 0.1 (2.6493 − 0.3) = 0.2349
And 𝐾2 = 0.1 𝑓(𝑥3 + ℎ, 𝑦3 + 𝐾1 ) = 0.1 𝑓(0.4, 2.6493 + 0.2349)
= 0.1 𝑓(0.4,2.8842)
= 0.1 (2.8842 − 0.4)
= 0.2484
Therefore,
1
𝑦4 = 𝑦(0.4) = 2.6493 + (0.2349 + 0.2484)
2
∴ 𝑦3 = 2.8909
Hence the required approximation correct up to 3-decimal places is 2.891.
Example: Use second order Runge -Kutta method to solve the initial value
problem 𝒚′ = 𝟑𝒙 + 𝒚𝟐 with 𝒚(𝟏) = 𝟏.2 and find the value of 𝒚(𝟏. 𝟏) with 𝒉 =
𝟎. 𝟏.
Solution:
𝑑𝑦
We are given that = 3𝑥 + 𝑦 2 , where 𝑦(1) = 1.2.
𝑑𝑥
For 𝑛 = 1,
1
𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + (𝐾1 + 𝐾2 )
2
Here 𝐾1 = 0.1 𝑓(𝑥0 , 𝑦0 ) = 0.1 𝑓(1,1.2)
= 0.1 (3(1) + 1.22 ) = 0.444
And 𝐾2 = 0.1 𝑓(𝑥0 + ℎ, 𝑦0 + 𝐾1 ) = 0.1 𝑓(1.1, 1.2 + 0.444)
= 0.1 𝑓(1.1,1.644)
= 0.1 (3(1.1) + 1.6442 )
= 0.60027
Therefore,
1
𝑦1 = 𝑦(1.1) = 1.2 + (0.444 + 0.60027)
2
∴ 𝑦1 = 1.72214
Fourth order R-K Method:
𝑑𝑦
Let’s consider = 𝑓(𝑥, 𝑦) with 𝑦(𝑥0 ) = 𝑦0 .
𝑑𝑥
𝐾4 = ℎ 𝑓(𝑥𝑛−1 + ℎ, 𝑦𝑛−1 + 𝐾3 )
Example: Use RK-4 method to solve the initial value problem 𝒚′ = 𝒕 − 𝒚 with
𝒚(𝟎) = 𝟏 and find the value of 𝒚(𝟎. 𝟐) correct to five decimal places with 𝒉 =
𝟎. 𝟏.
𝑑𝑦
Solution: We are given that = 𝑡 − 𝑦 with 𝑦(0) = 1.
𝑑𝑡
Now, for 𝑛 = 2,
1
𝑦2 = 𝑦(𝑡2 ) = 𝑦1 + (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 )
6
Here
𝐾1 = 0.1 𝑓(𝑡1 , 𝑦1 )
= 0.1 𝑓(0.1,0.909675)
= 0.1 (0.1 − 0.909675)
= −0.080968
ℎ 𝐾1
Now, 𝐾2 = ℎ 𝑓 (𝑡1 + , 𝑦1 + )
2 2
0.1 − 0.080968
= 0.1 𝑓 (0.1 + , 0.909675 + )
2 2
𝐾4 = ℎ 𝑓(𝑥𝑛−1 + ℎ, 𝑦𝑛−1 + 𝐾3 )
For 𝑛 = 1,
1
𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 )
6
Here
𝐾1 = ℎ 𝑓(𝑥0 , 𝑦0 )
= 0.1 𝑓(0,1)
= 0.1 (−2(1) + 0 + 4)
= 0.2
ℎ 𝐾1
Now, 𝐾2 = ℎ 𝑓 (𝑥0 + , 𝑦0 + )
2 2
0.1 0.2
= 0.1 𝑓 (0 + ,1 + )
2 2
Now, for 𝑛 = 2,
1
𝑦2 = 𝑦(𝑥2 ) = 𝑦1 + (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 )
6
Here
𝐾1 = ℎ 𝑓(𝑥1 , 𝑦1 )
= 0.1 𝑓(0.1,1.18595)
= 0.1 (−2(1.18595) + 0.1 + 4)
= 0.17281
ℎ 𝐾1
Now, 𝐾2 = ℎ 𝑓 (𝑥1 + , 𝑦1 + )
2 2
0.1 0.17281
= 0.1 𝑓 (0.1 + , 1.18595 + )
2 2
Also,
ℎ 𝐾2
𝐾3 = ℎ 𝑓 (𝑥1 + , 𝑦1 + )
2 2
0.16053
= 0.1 𝑓 (0.15, 1.18595 + )
2
1. Using R-K (4th order) method, find the solution of the differential equation
(IVP)
𝑥𝑦′ = 𝑥 − 𝑦, 𝑦(2) = 2 at 2.3 correct up to five decimal places with ℎ =
0.1.
Ans: 2.01956
2. Using R-K (4th order) method, find the solution of the differential equation
𝑦
(IVP) 𝑦 ′ = 3𝑥 + , 𝑦(0) = 1 at 0.2 correct to four decimal places with
2
ℎ = 0.1.
Ans: 1.1668
𝐾4 = ℎ 𝑓(𝑡𝑛−1 + ℎ, 𝑥𝑛−1 + 𝐾3 )
For 𝑛 = 1,
1
𝑥1 = 𝑥(𝑡1 ) = 𝑥0 + (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 ) = 681.24
6
For 𝑛 = 2,
1
𝑥2 = 𝑥(𝑡2 ) = 𝑥1 + (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 ) = 11455
6
The exact solution of the ordinary differential equation is given by
x(t ) = 10.714 + 39.286e −3.5t
Figure 1 compares the exact solution with the numerical solution using Runge-
Kutta 4th order method using different step sizes.
Table 1 and Figure 2 show the effect of step size on the value of the calculated
temperature at t = 3 min.
Table 1 Value of concentration of salt at 3 minutes for different step sizes.