Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

RK2 Method

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Runge-Kutta (RK) Methods

Runge-Kutta derived methods of many orders (2, 3, 4 and 6), we will learn methods of
order 2 and 4 only. Before moving towards RK method of order 2 let us see Modified
Euler method, which is an improvement in Euler’s method. That is for
1
𝑦𝑖+1 = 𝑦𝑖 + ℎ 𝑓(𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0, 1, 2, … with 𝑦0 = 𝛼,
we take average of two consecutive iterations as
ℎ 1
𝑦𝑖+1 = 𝑦𝑖 + ( 𝑓(𝑥𝑖 , 𝑦𝑖 ) + 𝑓(𝑥𝑖+1 , 𝑦𝑖+1 )), 𝑖 = 0, 1, 2, … with 𝑦0 = 𝛼 .
2

In Modified Euler method, we have to calculate same iteration two times (one using
Euler’s method and again same using Modified Euler Method).
RK method of order 2
RK- method of order 2 is actually a different form of Modified Euler method. Since RK-
2 and Modified Euler methods are almost same, we will use only one of them that is RK-
2 method. That is for IVP
𝑑𝑦
= 𝑓(𝑥, 𝑦) , 𝑦(𝑥0 ) = 𝑦0
𝑑𝑥
Then RK-2 method is given by
1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 𝑘2 ], 𝑖 = 0, 1, 2, …
2
where
𝑘1 = ℎ𝑓(𝑥𝑖 , 𝑦𝑖 ), and 𝑘2 = ℎ𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 )
Example
Solve the initial value problem 𝑦 𝑦 ′ = 𝑥, 𝑦(0) = 1, using the RK-2 method in 0 ≤ 𝑥 ≤
0.8, with ℎ = 0.2. If the exact solution of the differential equation is y = √(𝑥 2 + 1).
Compare the result with the exact solution at 𝑥 = 0.8.
Solution
We know that the RK-2 method is given by
1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 𝑘2 ], 𝑖 = 0,1,2, …
2
where
𝑘1 = ℎ𝑓(𝑥𝑖 , 𝑦𝑖 ) and 𝑘2 = ℎ𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 )
𝑥 𝑥𝑛 −𝑥0
Here 𝑓(𝑥, 𝑦) = , 𝑦(0) = 1 implies 𝑥0 = 0, 𝑦0 = 1, and 𝑛 = =4
𝑦 ℎ
𝑥𝑖
So 𝑘1 = ℎ𝑓(𝑥𝑖 , 𝑦𝑖 ) = 0.2
𝑦𝑖

𝑥𝑖 +ℎ
and 𝑘2 = ℎ𝑓(𝑥𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ) = 0.2
𝑦𝑖 +𝑘1

𝑥0 0
Now for 𝒊 = 𝟎, 𝑘1 = ℎ𝑓(𝑥0 , 𝑦0 ) = 0.2 = 0.2 ( ) = 0,
𝑦0 1

𝑥0 +ℎ 0+0.2
𝑘2 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘1 ) = 0.2 ( ) = 0.2 ( 1+0 ) = 0.04
𝑦0 +𝑘1

𝟏 𝟏
𝒚𝟏 = 𝒚𝟎 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟏 + (𝟎 + 𝟎. 𝟎𝟒) = 𝟏. 𝟎𝟐, at 𝑥1 = 0.2
𝟐 𝟐
𝑥1
For 𝒊 = 𝟏, 𝑘1 = ℎ𝑓(𝑥1 , 𝑦1 ) = 0.2 = 0.03922,
𝑦1

𝑥1 +ℎ
𝑘2 = 0.2 ( ) = 0.07553
𝑦1 +𝑘1

𝟏 𝟏
𝒚𝟐 = 𝒚𝟏 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟏. 𝟎𝟐 + (𝟎. 𝟎𝟑𝟗𝟐𝟐 + 𝟎. 𝟎𝟕𝟓𝟓𝟑) = 𝟏. 𝟎𝟕𝟕𝟑𝟕, at 𝑥2 = 0.4
𝟐 𝟐
𝑥2
For 𝒊 = 𝟐, 𝑘1 = 0.2 = 0.07425,
𝑦2

𝑥2 +ℎ
𝑘2 = 0.2 ( ) = 0.10420
𝑦2 +𝑘1

𝟏
𝒚𝟑 = 𝒚𝟐 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟏. 𝟏𝟔𝟔𝟔𝟎, at 𝑥3 = 0.6
𝟐
𝑥3
For 𝒊 = 𝟑, 𝑘1 = 0.2 = 0.10286,
𝑦3

𝑥3 +ℎ
𝑘2 = 0.2 ( ) = 0.12604
𝑦3 +𝑘1

𝟏
𝒚𝟒 = 𝒚𝟑 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟏. 𝟐𝟖𝟏𝟎𝟓, at 𝑥4 = 0.8
𝟐

Since at 𝑥 = 0.8, the exact value is y(0.8) = √(0.82 + 1)=1.28062


Error = |1.28062-1.28105|= 0.00043
We can see that RK-2 method is more accurate than Euler’s method for the same h.
Practice Questions
Q. Use RK-2 method to approximate the solutions for the initial value problem
𝑦 ′ = 𝑡𝑒 3𝑡 − 2y, 𝑦(0) =0, in 0 ≤ 𝑡 ≤ 1, with ℎ = 0.25. If the exact solution of the
1 1 1
differential equation is y(t) = 𝑡𝑒 3𝑡 − 𝑒 3𝑡 + 𝑒 −2𝑡 , find error at 𝑡 =1.
5 25 25

Solution: We know that the RK-2 method is given by


1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 𝑘2 ], 𝑖 = 0,1,2, …
2
where
𝑘1 = ℎ𝑓(𝑡𝑖 , 𝑦𝑖 ) and 𝑘2 = ℎ𝑓(𝑡𝑖 + ℎ, 𝑦𝑖 + 𝑘1 )
for f(t, y) = 𝑡𝑒 3𝑡 − 2y, 𝑡0 = 0, 𝑦0 = 0
For 𝑖 = 0, 𝑘1 = 0, 𝑘2 = 0.13231,
1
𝑦1 = 𝑦0 + [𝑘1 + 𝑘2 ] = 0.066155, at 𝑡1 = 0.25
2

For 𝑖 = 1, 𝑘1 = 0.099235,
𝑘2 = 0.477516,
1
𝑦2 = 𝑦1 + [𝑘1 + 𝑘2 ] = 0.354531, at 𝑡2 = 0.5
2

For 𝑖 = 2, 𝑘1 = 0.382946,
𝑘2 = 1.410212,
1
𝑦3 = 𝑦2 + [𝑘1 + 𝑘2 ] = 1.251110, at 𝑡3 = 0.75
2

For 𝑖 = 3, 𝑘1 = 1.153395,
𝑘2 = 3.819132,
1
𝑦4 = 𝑦3 + [𝑘1 + 𝑘2 ] = 3.737374 , at 𝑡4 = 1
2

At t = 1, the exact solution is y(1) = 3.21910,


Error = |3.2191-3.73737| = 0.51827
Q. Use RK-2 method to approximate the solutions for the initial value problem 𝑦 ′ =
1 + y/t, 𝑦(1) = 2, in 1 ≤ 𝑡 ≤ 2, with ℎ = 0.25. Find error if the exact solution of the
differential equation is y(t) = 𝑡 ln 𝑡 + 2𝑡.
Solution: We know that the RK-2 method is given by
1
𝑦𝑖+1 = 𝑦𝑖 + [𝑘1 + 𝑘2 ], 𝑖 = 0,1,2, …
2
where
𝑘1 = ℎ𝑓(𝑡𝑖 , 𝑦𝑖 ) and 𝑘2 = ℎ𝑓(𝑡𝑖 + ℎ, 𝑦𝑖 + 𝑘1 )
𝑦
where 𝑓(𝑡, 𝑦) = 1 + , 𝑡0 = 1, 𝑦0 = 2
𝑡

For 𝑖 = 0, 𝑘1 = 0.75,
𝑘2 = 0.80,
𝟏
𝒚𝟏 = 𝒚𝟎 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟐. 𝟕𝟕𝟓, at 𝑡1 = 1.25
𝟐

For 𝑖 = 1, 𝑘1 = 0.805,
𝑘2 = 0.846667,
𝟏
𝒚𝟐 = 𝒚𝟏 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟑. 𝟔𝟎𝟎𝟖𝟑𝟒, at 𝑡2 = 1.5
𝟐

For 𝑖 = 2, 𝑘1 = 0.850139,
𝑘2 = 0.885853,
𝟏
𝒚𝟑 = 𝒚𝟐 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟒. 𝟒𝟔𝟖𝟖𝟑, at 𝑡3 = 1.75
𝟐

For 𝑖 = 3, 𝑘1 = 0.888404,
𝑘2 = 0.919654,
𝟏
𝒚𝟒 = 𝒚𝟑 + [𝒌𝟏 + 𝒌𝟐 ] = 𝟓. 𝟑𝟕𝟐𝟖59, at 𝑡4 = 2
𝟐
At 𝑡 = 2, exact solution is y(2) = 5.386294,
Therefore, Error = 0.013435

Q. Use RK-2 method to approximate the solutions for the initial value problem
y 2⁄
𝑦′ = 1 + t , 𝑦(1) = −(ln 2)
−1
in 1 ≤ 𝑡 ≤ 2, with ℎ = 0.1.
−1
If the exact solution is y(t) = , then find error at t=1.5, and t=2.
ln(𝑡+1)

You might also like