You are on page 1of 15

NUMERICAL SOLUTION OF

ORDINARY DIFFERENTIAL EQUATIONS

Syllabus :- Initial value problems - Single step methods: Taylor’s series


method – Truncation error – Euler and Improved Euler methods – Fourth
order Runge – Kutta method – Multistep method: Milne’s predictor -
corrector method.

Introduction
The solution of an ordinary differential equation (ODE) is a specific
relation between the dependent variable and independent variable which
satisfies the original differential equation.
The general solution of a ODE of nth order has ‘n’ arbitrary
constants. So, to find the particular solution of n th order equation, ‘n’
conditions are required.
These ‘n’ conditions will be provided by the values of the dependent
variable (or) its derivative for ‘n’ specific values of the independent
variable.
If all the ‘n’ conditions are specified only for the initial value of the
independent variable ‘x’ then the problem is called an initial value
problem.(IVP)
If all the ‘n’ conditions are specified for two or more values of the
independent variable ‘x’ then the problem is called a boundary value
problem.(BVP)
𝑑2 𝑦 𝑑𝑦
Example for IVP : = 𝑓 (𝑥, 𝑦, 𝑑𝑥 ) , 𝑠𝑢𝑏𝑗𝑒𝑐𝑡 𝑡𝑜 𝑦(𝑥0 ) = 𝑎 &𝑦 ′ (𝑥0 ) = 𝑏
𝑑𝑥 2

𝑑2 𝑦 𝑑𝑦
Example for BVP : = 𝑓 (𝑥, 𝑦, 𝑑𝑥 ) , 𝑠𝑢𝑏𝑗𝑒𝑐𝑡 𝑡𝑜 𝑦(𝑥0 ) = 𝑎 & 𝑦(𝑥𝑛 ) = 𝑏
𝑑𝑥 2

The solution of IVP can be obtained by the following two methods.


1) Single step method: Here the information about the curve at one
point will be used and we do not iterate the solution. This method
includes more evaluations of the function.
Examples : Taylor’s series method, Euler & Improved Euler methods,
Runge-Kutta method.
2) Multi step method: Here fewer prior evaluations of the function are
required to find the solution at a point and iterations will be carried out till
sufficient accuracy is achived.
Example : Milne’s Predictor Corrector method.
Taylor’s series method for first order ODE
𝑑𝑦
Aim : To find the solution of = 𝑦 ′ = 𝑓 (𝑥, 𝑦) − − − − − − − − − (1)
𝑑𝑥

Subject to the initial condition 𝑦(𝑥0 ) = 𝑦0−−−−−−−−−−(2)

Now, we expand y(x) about the point 𝑥 = 𝑥0 in a Taylor’s series in powers


of (𝑥 − 𝑥0 ).

Formula :

(𝑥 − 𝑥0 ) ′ (𝑥 − 𝑥0 )2 ′′ (𝑥 − 𝑥0 )3 ′′′
𝑦(𝑥 ) = 𝑦(𝑥0 ) + 𝑦 (𝑥0 ) + 𝑦 (𝑥0 ) + 𝑦 (𝑥0 ) + −
1! 2! 3!
− −(3)

(or)

(𝑥 − 𝑥0 ) ′ (𝑥 − 𝑥0 )2 ′′ (𝑥 − 𝑥0 )3 ′′′
𝑦(𝑥 ) = 𝑦0 + 𝑦0 + 𝑦0 + 𝑦0 + − − − − −
1! 2! 3!
− −(3)
𝒉 𝒉𝟐 𝒉𝟑
i.e., 𝒚𝟏 = 𝒚(𝒙𝟏 ) = 𝒚𝟎 + 𝒚𝟎 ′ + 𝒚𝟎 ′′ + 𝒚𝟎 ′′′ + − − − − − − −(𝟒)
𝟏! 𝟐! 𝟑!

where 𝒉 = 𝒙 − 𝒙𝟎 and 𝒙𝟏 = 𝒙𝟎 + 𝒉

To find 𝒚′𝟎 , 𝒚′′𝟎 , 𝒚′′′


𝟎 , − − − − we use (1) and its derivative at 𝒙 = 𝒙𝟎 .

Though (4) is an infinite series, we can truncate it at any convenient


term, if ‘h’ is small and the accuracy is obtained.

Using 𝒚𝟏 we can find 𝒚𝟐 , 𝒚𝟑,−−−−−−−

By expanding y(x) in a Taylor’s series about the point = 𝑥1 , we get

ℎ ′ ℎ2 ′′ ℎ3 ′′′
𝑦2 = 𝑦(𝑥2 ) = 𝑦1 + 𝑦1 + 𝑦1 + 𝑦1 + − − − − − − −(5)
1! 2! 3!

Proceeding like this, we get the general formula


𝒉 ′ 𝒉𝟐 ′′ 𝒉𝟑 ′′′
𝒚𝒏+𝟏 = 𝒚𝒏 + 𝒚 𝒏 + 𝒚 + 𝒚𝒏 + − − − − − − −(𝟔)
𝟏! 𝟐! 𝒏 𝟑!

Remark : The truncation error is 𝑂(ℎ𝑛+1 ).

By including more number of terms for calculation, the error can be


reduced further.

If ‘h’ is small and the term after ‘n’ terms are neglected, the error is
ℎ𝑛
𝑓 𝑛 (𝜃) 𝑤ℎ𝑒𝑟𝑒 𝑥0 < 𝜃 < 𝑥1 𝑖𝑓 𝑥1 − 𝑥0 = ℎ.
𝑛!

Problems:
𝑑𝑦
1) Solve = 𝑥 + 𝑦 given y(1)=0 and determine y(1.1) by Taylor’s series
𝑑𝑥
method.

Solution :

Compare the given condition y(1)=0 with 𝑦(𝑥0 ) = 𝑦0 we get 𝑥0 = 1 &𝑦0 = 0

To find y(1.1)=y(x1)= 𝑦(𝑥0 + ℎ)

𝑦(𝑥0 + ℎ) = 𝑦(1 + ℎ) = 𝑦(1.1) ⟹ 1 + ℎ = 1.1 ⟹ ℎ = 0.1


ℎ ℎ2 ℎ3
Therefore 𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + 1! 𝑦0 ′ + 𝑦 ′′ + 𝑦0 ′′′ + − − − − − − −(1)
2! 0 3!

𝑦 ′ = 𝑥 + 𝑦⟹ 𝑦0 ′ = 𝑥0 + 𝑦0 = 1 + 0 = 1

𝑦 ′′ = 1 + 𝑦 ′ ⟹ 𝑦0 ′′ = 1 + 𝑦0 ′ = 1 + 1 = 2

𝑦 ′′′ = 𝑦 ′′ ⟹ 𝑦0 ′′′ = 𝑦0 ′′ = 2

𝑦 ′𝑣 = 𝑦 ′′′ ⟹ 𝑦0 ′𝑣 = 𝑦0 ′′′ = 2 etc.,

By substituting the above derived values in (1), we get

0.1 (0.1)2 (0.1)3 (0.1)4


𝑦1 = 𝑦(1.1) = 0 + (1) + (2) + (2) + (2) + − − − − − − −
1! 2! 3! 4!

i.e., 𝑦1 = 𝑦(1.1) = 0.11034

***********************************************************
2) Using Taylor’s series method , find the value of y(0.1), given
𝑑𝑦
= 𝑥 2 + 𝑦 2 and y(0)=1. Correct to four decimal places.
𝑑𝑥

Solution :

Compare the given condition y(0)=1 with 𝑦(𝑥0 ) = 𝑦0 we get 𝑥0 = 0 &𝑦0 = 1

To find y(0.1)=y(x1)= 𝑦(𝑥0 + ℎ)

𝑦(𝑥0 + ℎ) = 𝑦(0 + ℎ) = 𝑦(0.1) ⟹ 0 + ℎ = 0.1 ⟹ ℎ = 0.1


ℎ ℎ2 ℎ3
Therefore 𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + 1! 𝑦0 ′ + 𝑦 ′′ + 𝑦0 ′′′ + − − − − − − −(1)
2! 0 3!

𝑦 ′ = 𝑥 2 + 𝑦 2 --------------------⟹ 𝑦0 ′ = 𝑥0 2 + 𝑦0 2 = 0 + 1 = 1

𝑦 ′′ = 2𝑥 + 2𝑦𝑦 ′ ------------------⟹ 𝑦0 ′′ = 2𝑥0 + 2𝑦0 𝑦0 ′ = 2

𝑦 ′′′ = 2 + 2𝑦𝑦 ′′ + 2(𝑦 ′ )2 ----------⟹ 𝑦0 ′′′ = 2 + 2𝑦0 𝑦0 ′′ + 2(𝑦0 ′ )2 =8

𝑦 ′𝑣 = 2𝑦𝑦 ′′′ + 2𝑦 ′′ 𝑦 ′ + 4𝑦 ′ 𝑦 ′′

= 2𝑦𝑦 ′′′ + 6𝑦 ′′ 𝑦 ′ -------------⟹ 𝑦0 ′𝑣 = 2𝑦0 𝑦𝑜 ′′′ + 6𝑦𝑜 ′′ 𝑦0 ′ = 28

By substituting the above derived values in (1), we get

𝑦1 = 𝑦(0.1) = 1.1115

***********************************************************

3) Using Taylor’s series method , compute y(0.2) and y(0.4), correct to 4


𝑑𝑦
decimal places given = 1 − 2𝑥𝑦 and y(0)=0.
𝑑𝑥

Solution :

Compare the given condition y(0)=1 with 𝑦(𝑥0 ) = 𝑦0 we get 𝑥0 = 0 &𝑦0 = 1

To find y(0.2)=y(x1)= 𝑦(𝑥0 + ℎ)

𝑦(𝑥0 + ℎ) = 𝑦(0 + ℎ) = 𝑦(0.2) ⟹ 0 + ℎ = 0.2 ⟹ ℎ = 0.2


ℎ ℎ2 ℎ3
Therefore 𝑦1 = 𝑦(𝑥1 ) = 𝑦0 + 1! 𝑦0 ′ + 𝑦 ′′ + 𝑦0 ′′′ + − − − − − − −(1)
2! 0 3!

𝑦 ′ = 1 − 2𝑥𝑦 -------------------⟹ 𝑦0 ′ = 1 − 2𝑥0 𝑦0 =1

𝑦 ′′ = −2(𝑥𝑦 ′ + 𝑦) ------------------⟹𝑦0 ′ ′=0

𝑦 ′′′ = −2(𝑥𝑦 ′′ + 𝑦 ′ + 𝑦 ′ )

= −2(𝑥𝑦 ′′ + 2𝑦 ′ ) -------------⟹𝑦0 ′′′ = −4


𝑦 ′𝑣 = −2(𝑥𝑦 ′′′ + 𝑦 ′′ + 2𝑦 ′′ )

= −2(𝑥𝑦 ′′′ + 3𝑦 ′′ ---------------⟹𝑦0 ′𝑣 = 0

𝑦 𝑣 = −2(𝑥𝑦 ′𝑣 + 4𝑦 ′′′ --------------⟹𝑦0 𝑣 =32

By substituting the above derived values in (1), we get

𝑦1 = 𝑦(0.2) = 0.1948---------------------------(2)

To find y(0.4)=y(x2)= 𝒚(𝒙𝟏 + 𝒉) = 𝒚(𝟎. 𝟐 + 𝟎. 𝟐)

Therefore

ℎ ′ ℎ2 ′′ ℎ3 ′′′
𝑦2 = 𝑦(0.4) = 𝑦1 + 𝑦 + 𝑦1 + 𝑦1 + − − − − − − −(3)
1! 1 2! 3!

𝑦 ′ = 1 − 2𝑥𝑦 --------------⟹ 𝑦1 ′ = 1 − 2𝑥1 𝑦1 = 1 − 2(0.2)(0.1948) = 0.9221


=

𝑦 ′′ = −2(𝑥𝑦 ′ + 𝑦) ------------------⟹𝑦1 ′ ′ = −2(𝑥1 𝑦1 ′ + 𝑦1 ) = −0.7583

𝑦 ′′′ = −2(𝑥𝑦 ′′ + 𝑦 ′ + 𝑦 ′ )

= −2(𝑥𝑦 ′′ + 2𝑦 ′ ) -------------⟹𝑦1 ′′′ = −3.3851

𝑦 ′𝑣 = −2(𝑥𝑦 ′′′ + 𝑦 ′′ + 2𝑦 ′′ )

= −2(𝑥𝑦 ′′′ + 3𝑦 ′′ ---------------⟹𝑦1 ′𝑣 = 5.9041

By substituting the above derived values in (3), we get

𝑦2 = 𝑦(0.4) = 0.3599

***********************************************************

Practice problems

1) Find y(0.1) given 𝑦 ′ = 𝑥 2 𝑦 − 1, 𝑦(0) = 1

2) Solve 𝑦 ′ = 𝑥𝑦 + 𝑦 2 , 𝑦(0) = 1 at x=0.1, 0.2, 0.3


𝑑𝑦 1
3) Obtain y(4.4) given = 𝑥 2 +𝑦 , 𝑦(4) = 4 by taking h=0.2
𝑑𝑥

𝑦2
4) Solve 𝑦 ′ = 𝑥 + 10 , y(1.8)=0 for y(2).
Euler’s method
𝑑𝑦
Aim :To find the solution of = 𝑦 ′ = 𝑓(𝑥, 𝑦) − − − − − − − − − (1)
𝑑𝑥

Subject to the initial condition 𝑦(𝑥0 ) = 𝑦0−−−−−−−−−−(2)

Formula :𝒚(𝒙 + 𝒉) = 𝒚(𝒙) + 𝒉𝒇(𝒙, 𝒚) (or) 𝒚𝒏+𝟏 = 𝒚𝒏 + 𝒉𝒇(𝒙𝒏 , 𝒚𝒏 )---------(I)

Remark : Error is of order ℎ2

Problems :

1) Given 𝑦 ′ = −𝑦 and y(0)=1. Determine the value of y at

x =(0.01)(0.01)(0.04) by Euler method.


𝑑𝑦
Solution : Comparing the given equation with = 𝑓(𝑥, 𝑦)𝑎𝑛𝑑 𝑦(𝑥0 ) = 𝑦0 we
𝑑𝑥
write, f(x,y)=−y and 𝑥0 = 0 𝑎𝑛𝑑 𝑦0 = 1

Given step size h= 0.01

To find 𝑦1 = 𝑦(𝑥1 ) = 𝑦(0.01), 𝑦2 = 𝑦(𝑥2 ) = 𝑦(0.02), 𝑦3 = 𝑦(𝑥3 ) = 𝑦(0.03), 𝑦4 =


𝑦(𝑥4 ) = 𝑦(0.04)

By putting n=0 in the formula (I),

𝒚𝟏 = 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 ) = 1 + 0.01(−𝑦0 ) = 1 + 0.01(−1) = 0.99

By putting n=1 in the formula (I),

𝒚𝟐 = 𝒚𝟏 + 𝒉𝒇(𝒙𝟏 , 𝒚𝟏 ) = 0.99 + 0.01(−𝑦1 ) = 0.99 + 0.01(−0.99) = 0.9801

By putting n=2 in the formula (I),

𝒚𝟑 = 𝒚𝟐 + 𝒉𝒇(𝒙𝟐 , 𝒚𝟐 ) = 0.9801 + 0.01(−𝑦2 ) = 0.9801 + 0.01(−0.9801) = 0.9703

By putting n=3 in the formula (I),

𝒚𝟒 = 𝒚𝟑 + 𝒉𝒇(𝒙𝟑 , 𝒚𝟑 ) = 0.9703 + 0.01(−𝑦3 ) = 0.9703 + 0.01(−9703) = 0.9606

***********************************************************
2) Given 𝑦 ′ = 𝑥 + 𝑦 and y(0)=1. Determine the value of y at

x =(0.0)(0.2)(1.0) using Euler method.


𝑑𝑦
Solution : Comparing the given equation with = 𝑓(𝑥, 𝑦)𝑎𝑛𝑑 𝑦(𝑥0 ) = 𝑦0 we
𝑑𝑥
write, f(x,y)=x+y and 𝑥0 = 0 𝑎𝑛𝑑 𝑦0 = 1

Given step size h= 0.2

To find 𝑦1 = 𝑦(𝑥1 ) = 𝑦(0.2), 𝑦2 = 𝑦(𝑥2 ) = 𝑦(0.4), 𝑦3 = 𝑦(𝑥3 ) = 𝑦(0.6), 𝑦4 = 𝑦(𝑥4 ) =


𝑦(0.8), 𝑦5 = 𝑦(𝑥5 ) = 𝑦(1.0)

By putting n=0 in the formula (I),

𝒚𝟏 = 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 ) = 1 + 0.2(𝑥0 + 𝑦0 ) = 1 + 0.2(0 + 1) = 1.2

By putting n=1 in the formula (I),

𝒚𝟐 = 𝒚𝟏 + 𝒉𝒇(𝒙𝟏 , 𝒚𝟏 ) = 1.2 + 0.2(𝑥1 + 𝑦1 ) = 1.2 + 0.2(0.2 + 1.2) = 1.48

By putting n=2 in the formula (I),

𝒚𝟑 = 𝒚𝟐 + 𝒉𝒇(𝒙𝟐 , 𝒚𝟐 ) = 1.48 + 0.2(𝑥2 + 𝑦2 ) = 1.2 + 0.2(0.4 + 1.48) = 1.856

By putting n=3 in the formula (I),

𝒚𝟒 = 𝒚𝟑 + 𝒉𝒇(𝒙𝟑 , 𝒚𝟑 ) = 1.856 + 0.2(𝑥3 + 𝑦3 ) = 1.856 + 0.2(0.6 + 1.856) = 2.3472

By putting n=4 in the formula (I),

𝒚𝟓 = 𝒚𝟒 + 𝒉𝒇(𝒙𝟒 , 𝒚𝟒 ) = 2.3472 + 0.2(𝑥4 + 𝑦4 ) = 2.3472 + 0.2(0.8 + 2.3472)


= 2.9467

***********************************************************
Improved Euler’s Method

Formula:
𝒉
𝒚𝒏+𝟏 = 𝒚𝒏 + [𝒇(𝒙𝒏 , 𝒚𝒏 ) + 𝒇(𝒙𝒏 + 𝒉, 𝒚𝒏 + 𝒉𝒇(𝒙𝒏 , 𝒚𝒏 ))] -----------(II)
𝟐

Problem 1 :Given 𝑦 ′ = 𝑥 2 − 𝑦 and y(0)=1. Find correct to 4 decimal


places, the value of y(0.1) by Improved Euler method.
𝑑𝑦
Solution :Comparing the given equation with = 𝑓(𝑥, 𝑦)𝑎𝑛𝑑 𝑦(𝑥0 ) = 𝑦0 we
𝑑𝑥
write, f(x,y)=𝑥 2 − 𝑦 and 𝑥0 = 0 , 𝑦0 = 1

Let the step size h be 0.1 Then formula (II) becomes


𝟎.𝟏
𝒚𝟏 = 𝒚(𝒙𝟏 ) = 𝒚(𝟎. 𝟏) = 𝒚𝟎 + 𝟐 [𝒇(𝒙𝟎 , 𝒚𝟎 ) + 𝒇(𝒙𝟎 + 𝒉, 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 ))]---(1)

𝑓 (𝑥0 , 𝑦0 ) = 𝑥0 2 − 𝑦0 = 0 − 1 = −1 -----------------------------(i)

𝑦0 + ℎ𝑓 (𝑥0 , 𝑦0 ) = 1 + (0.1)(−1) = 0.9 ----------------(ii)

𝑓(𝑥0 + ℎ, 𝑦0 + ℎ𝑓 (𝑥0 , 𝑦0 )) = 𝑓 (0.1, 0.9) = (0.1)2 − 0.9 = −0.89 ------(iii)

Substituting the values derived in (i), (ii), (iii) in (1) we get

𝟎. 𝟏
𝒚𝟏 = 𝒚(𝒙𝟏 ) = 𝒚(𝟎. 𝟏) = 𝟏 + [−𝟏 − 𝟎. 𝟖𝟗] = 𝟎. 𝟗𝟎𝟓𝟓
𝟐
***********************************************************

Problem 2 :Given 𝑦 ′ = 𝑦 + 𝑒 𝑥 and y(0)=0. Find the value of y at x=0.2 by


Improved Euler method.
𝑑𝑦
Solution :Comparing the given equation with = 𝑓(𝑥, 𝑦)𝑎𝑛𝑑 𝑦(𝑥0 ) = 𝑦0 we
𝑑𝑥
write, f(x,y)= 𝑦 + 𝑒 𝑥 and 𝑥0 = 0 , 𝑦0 = 0

Let the step size h be 0.2 Then formula (II) becomes


𝟎.𝟐
𝒚𝟏 = 𝒚(𝒙𝟏 ) = 𝒚(𝟎. 𝟐) = 𝒚𝟎 + 𝟐 [𝒇(𝒙𝟎 , 𝒚𝟎 ) + 𝒇(𝒙𝟎 + 𝒉, 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 ))]---(1)

𝑓 (𝑥0 , 𝑦0 ) = 𝑦0 + 𝑒 𝑥0 = 0 + 𝑒 0 = 1 -----------------------------(i)

𝑦0 + ℎ𝑓 (𝑥0 , 𝑦0 ) = 0 + (0.2)(1) = 0.2 ----------------(ii)


𝑓(𝑥0 + ℎ, 𝑦0 + ℎ𝑓 (𝑥0 , 𝑦0 )) = 𝑓 (0.2, 0.2) = 0.2 + 𝑒 0.2 = 1.4214 ------(iii)

Substituting the values derived in (i), (ii), (iii) in (1) we get

𝟎. 𝟐
𝒚𝟏 = 𝒚(𝒙𝟏 ) = 𝒚(𝟎. 𝟐) = 𝟎 + [𝟏 + 𝟏. 𝟒𝟐𝟏𝟒] = 𝟎. 𝟐𝟒𝟐𝟏𝟒
𝟐

Practice Problems:

1) Use Euler method to find y(0.4) given 𝑦 ′ = 𝑥𝑦, 𝑦(0) = 1

2) Compute y(0.2), y(0.4), y(0.6) by Euler’s method , given 𝑦 ′ =


log(𝑥 + 𝑦) , 𝑦(0) = 1

3) By improved Euler’s method, determine y(0.1) given


𝑦−𝑥
𝑦′ = , 𝑦 (0) = 1
𝑦+𝑥

4) Find by improved Euler’s method to get y(1.4) given


𝑑𝑦 2𝑦
= + 𝑥 3 if y(1)=0.5
𝑑𝑥 𝑥

5) Using improved Euler’s method, find the value of y at x=0.2

Given 𝑦 ′ = −𝑥𝑦 2 , 𝑦(0) = 2

***********************************************************
Fourth order Runge-Kutta method
Algorithm:
𝑘1 = ℎ𝑓(𝑥, 𝑦)
ℎ 𝑘1
𝑘2 = ℎ𝑓 (𝑥 + , 𝑦 + )
2 2
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥 + , 𝑦 + )
2 2
𝑘4 = ℎ𝑓(𝑥 + ℎ, 𝑦 + 𝑘3 )
1
𝛥𝑦 = (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
𝑦𝑛+1 = 𝑦𝑛 + 𝛥𝑦

1. Apply fourth order Runge-Kutta method to find 𝑦(0.2), given 𝑦 ′ = 𝑥 +


𝑦, 𝑦(0) = 1, ℎ = 0.1.

Answer:
𝑓 (𝑥, 𝑦) = 𝑥 + 𝑦, 𝑥0 = 0, 𝑦0 = 1, 𝑥1 = 0.1, 𝑥2 = 0.2

To find 𝒚(𝟎. 𝟏)
𝑘1 = ℎ𝑓(𝑥0 , 𝑦0 ) = 0.1(𝑥0 + 𝑦0 ) = 0.1(0 + 1) = 0.1
ℎ 𝑘1 0.1 0.1
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0 + ,1 + ) = 0.1𝑓 (0.05,1.05)
2 2 2 2
= 0.1(0.05 + 1.05) = 0.11
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓(0.05,1.055) = 0.1(0.05 + 1.055) = 0.1105
2 2
𝑘4 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘3 ) = 0.1𝑓(0.1,1.1105) = 0.1(0.1 + 1.1105) = 0.12105
1 1
𝛥𝑦 = (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ) = (0.1 + 2(0.11) + 2(0.1105) + 0.12105) = 0.1103
6 6
∴ 𝑦(0.1) = 𝑦1 = 𝑦0 + 𝛥𝑦 = 1 + 0.1103 = 1.1103

To find 𝒚(𝟎. 𝟐)
𝑓(𝑥, 𝑦) = 𝑥 + 𝑦, 𝑥1 = 0.1, 𝑦1 = 1.1103, ℎ = 0.1

𝑘1 = ℎ𝑓 (𝑥1 , 𝑦1 ) = 0.1(𝑥1 + 𝑦1 ) = 0.1(0.1 + 1.1103) = 0.1210


ℎ 𝑘1 0.1 0.1210
𝑘2 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓 (0.1 + , 1.1103 + ) = 0.1𝑓 (0.15,1.1708)
2 2 2 2
= 0.1320
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓(0.15,1.1763) = 0.1(0.15 + 1.1763) = 0.1326
2 2
𝑘4 = ℎ𝑓(𝑥1 + ℎ, 𝑦1 + 𝑘3 ) = 0.1𝑓(0.2,1.2429) = 0.1442
1 1
∴ 𝑦(0.2) = 𝑦2 = 𝑦1 + 𝛥𝑦 = 𝑦(0.1) + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ) = 1.1103 + (0.7947)
6 6
= 1.2428

2. Using R.K.method of fourth order, find 𝑦(0.8) correct to 4 decimal


places if
𝑦 ′ = 𝑦 − 𝑥 2 , 𝑦(0.6) = 1.7379 with ℎ = 0.1.

Answer:
𝑓 (𝑥, 𝑦) = 𝑦 − 𝑥 2 , 𝑥0 = 0.6, 𝑦0 = 1.7379, 𝑥1 = 0.7, 𝑥2 = 0.8, h = 0.1

To find 𝒚(𝟎. 𝟕)
𝑘1 = ℎ𝑓 (𝑥0 , 𝑦0 ) = 0.1𝑓(0.6, 1.7379) = (0.1)[1.7379 − (0.6)2 ] = 0.1378
ℎ 𝑘1
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0.65, 1.8068) = 0.1[1.8068 − 0.652 ] = 0.1384
2 2
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0.65,1.8071) = 0.1(1.8071 − 0.652 ) = 0.1385
2 2
𝑘4 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘3 ) = 0.1𝑓(0.7,1.8764) = 0.1(1.8764 − 0.72 ) = 0.1386
1
𝑦(0.7) = 𝑦1 = 1.7379 + (0.1378 + 2(0.1384) + 2(0.1385) + 0.1386) = 1.8763
6

To find 𝒚(𝟎. 𝟖)
𝑓(𝑥, 𝑦) = 𝑦 − 𝑥 2 , 𝑥1 = 0.7, 𝑦1 = 1.8763, ℎ = 0.1

𝑘1 = ℎ𝑓(𝑥1 , 𝑦1 ) = 0.1(𝑥1 + 𝑦1 ) = 0.1(1.8763 − 0.72 ) = 0.1386


ℎ 𝑘1
𝑘2 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓 (0.75,1.9456) = 0.1(1.9456 − 0.752 ) = 0.1383
2 2
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓(0.75,1.9455) = 0.1(1.9455 − 0.752 ) = 0.1383
2 2
𝑘4 = ℎ𝑓(𝑥1 + ℎ, 𝑦1 + 𝑘3 ) = 0.1𝑓 (0.8, 2.0146) = 0.1(2.0146 − 0.82 ) = 0.1375
1
∴ 𝑦(0.8) = 𝑦2 = 𝑦1 + 𝛥𝑦 = 1.8763 + (0.1386 + 2(0.1383) + 2(0.1383) + 0.1375)
6
= 2.0145

𝑑𝑦 𝑦 2 −𝑥 2
3. Using Runge-Kutta method of fourth order, solve = 𝑦 2 +𝑥 2 , at 𝑥 =
𝑑𝑥
0.2, 0.4given 𝑦(0) = 1.

Answer:
𝑦2 − 𝑥2
𝑓(𝑥, 𝑦) = , 𝑥 = 0, 𝑦0 = 1, 𝑥1 = 0.2, 𝑥2 = 0.4, ℎ = 0.2
𝑦2 + 𝑥2 0
To find 𝒚(𝟎. 𝟐)
12 − 02
𝑘1 = ℎ𝑓(𝑥0 , 𝑦0 ) = 0.2 ( ) = 0.2 (1) = 0.2
12 + 02
ℎ 𝑘1 1. 12 − 0.12
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.2𝑓(0.1, 1.1) = 0.2 ( 2 ) = 0.1967
2 2 1.1 + 0.12
ℎ 𝑘2 1. 09832 − 0.12
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.2𝑓(0.1,1.0983) = 0.2 ( ) = 0.1967
2 2 1.09832 + 0.12
1.1967 2 − 0.22
( ) ( )
𝑘4 = ℎ𝑓 𝑥0 + ℎ, 𝑦0 + 𝑘3 = 0.2𝑓 0.2,1.967 = 0.2 ( ) = 0.1891
1.19672 + 0.22
1
∆𝑦 = (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ) = 0.1959
6
𝑦(0.2) = 𝑦1 = 𝑦0 + 𝛥𝑦 = 1 + 0.1959 = 1.1959

To find 𝒚(𝟎. 𝟒)
𝑦2 − 𝑥2
𝑓 (𝑥, 𝑦) = , 𝑥 = 0.2, 𝑦1 = 1.1959 , ℎ = 0.2
𝑦2 + 𝑥2 1

1.19592 − 0.22
𝑘1 = ℎ𝑓(𝑥1 , 𝑦1 ) = 0.2 ( ) = 0.1891
1.19592 + 0.22
ℎ 𝑘1 1.1290552 − 0.32
𝑘2 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.2𝑓(0.3,1.29055) = 0.2 ( ) = 0.17949
2 2 1.1290552 + 0.32
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.2𝑓(0.3,1.28572) = 0.1793
2 2
𝑘4 = ℎ𝑓 (𝑥1 + ℎ, 𝑦1 + 𝑘3 ) = 0.2𝑓(0.4, 1.37528) = 0.1687
∴ 𝑦(0.4) = 𝑦2 = 𝑦1 + 𝛥𝑦 = 1.1959 + 0.1792 = 1. 3751

4. Given 𝑦 ′ + 𝑥𝑦 2 + 𝑦 = 0, 𝑦(0) = 1, find the value of 𝑦(0.2), by using Runge-


Kutta method of 4th order , with ℎ = 0.1

Answer
𝑓 (𝑥, 𝑦) = −(𝑥𝑦 2 + 𝑦), 𝑥0 = 0, 𝑦0 = 1, 𝑥1 = 0.1, 𝑥2 = 0.2

To find 𝒚(𝟎. 𝟏)
𝑘1 = ℎ𝑓 (𝑥0 , 𝑦0 ) = 0.1(−(𝑥0 𝑦0 2 + 𝑦0 )) = −0.1
ℎ 𝑘1
𝑘2 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0.05, 0.95) = −0.1((0.05)(0.95)2 + 0.95 ) = −0.0995
2 2
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥0 + , 𝑦0 + ) = 0.1𝑓 (0.05,0.9502) = −0.1((0.05)(0.9502)2 + 0.9502 )
2 2
= −0.0995
𝑘4 = ℎ𝑓(𝑥0 + ℎ, 𝑦0 + 𝑘3 ) = 0.1𝑓(0.1,0.9005) = −0.0982
1
𝑦1 = 𝑦0 + 𝛥𝑦 = 1 + (𝑘 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6 1
1
= 1 + (−0.1 + 2(−0.0995) + 2(−0.0995) − 0.0982) = 0.9006
6

To find 𝒚(𝟎. 𝟐)
𝑓(𝑥, 𝑦) = −(𝑥𝑦 2 + 𝑦), 𝑥1 = 0.1, 𝑦1 = 0.9006, ℎ = 0.1

𝑘1 = ℎ𝑓(𝑥1 , 𝑦1 ) = 0.1(0.1, 0.9006) = −0.0982


ℎ 𝑘1
𝑘2 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓 (0.15, 0.8515) = −0.0960
2 2
ℎ 𝑘2
𝑘3 = ℎ𝑓 (𝑥1 + , 𝑦1 + ) = 0.1𝑓 (0.15, 0.8526) = −0.0962
2 2
𝑘4 = ℎ𝑓 𝑥1 + ℎ, 𝑦1 + 𝑘3 ) = 0.1𝑓(0.2, 0.8044) = −0.0934
(
1
∴ 𝑦(0.2) = 𝑦2 = 𝑦1 + 𝛥𝑦 = 𝑦(0.1) + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
1
= 0.9006 + (−0.0982 + 2(−0.0960) + 2(−0.0962) = 0.0934)
6
= 0.8046

Fourth order Runge-Kutta method for solving second order ODE


𝑑2 𝑦 𝑑𝑦 2
1. Solve − 𝑥 (𝑑𝑥 ) + 𝑦 2 = 0 using Runge-Kutta method, for 𝑥 = 0.2,
𝑑𝑥 2
correct to four decimal
places. Given 𝑦(0) = 1, 𝑦 ′ (0) = 0.

Answer
Put 𝑦 ′ = 𝑧 and 𝑦 ″ = 𝑧 ′ .
Then the given equation reduces to
𝑑𝑦 𝑑𝑧
= 𝑧, = 𝑥𝑧 2 − 𝑦 2
𝑑𝑥 𝑑𝑥
Given 𝑥0 = 0, 𝑦0 = 1, 𝑧0 = 𝑦0 ′ = 0, ℎ = 0.2
Let 𝑓1 (𝑥, 𝑦, 𝑧) = 𝑧
𝑓2 (𝑥, 𝑦, 𝑧) = 𝑥𝑧 2 − 𝑦 2
Using Runge-Kutta formula,

𝑘1 = ℎ𝑓1 (𝑥0 , 𝑦0 , 𝑧0 ) 𝑙1 = ℎ𝑓2 (𝑥0 , 𝑦0 , 𝑧0 )


= 0.2𝑓1 (0,1,0) = 0.2 × 𝑓2 (0,1,0)
=0 = −0.2
ℎ 𝑘1 𝑙1 ℎ 𝑘1 𝑙1
𝑘2 = ℎ𝑓1 (𝑥0 + , 𝑦0 + , 𝑧0 + ) 𝑙2 = ℎ𝑓2 (𝑥0 + , 𝑦0 + , 𝑧0 + )
2 2 2 2 2 2
= 0.2𝑓1 (0,1,0) = 0.2𝑓2 (0.1,1, −0.1)
= −0.02 = −0.1998
ℎ 𝑘2 𝑙2 ℎ 𝑘2 𝑙2
𝑘3 = ℎ𝑓1 (𝑥0 + , 𝑦0 + , 𝑧0 + ) 𝑙3 = ℎ𝑓2 (𝑥0 + , 𝑦0 + , 𝑧0 + )
2 2 2 2 2 2
= 0.2𝑓1 (0.1,0.99, −0.0999) = 0.2𝑓2 (0.1,0.99, −0.0999)
= −0.01998 = −0.01958
𝑘4 = ℎ𝑓1 (𝑥0 + ℎ, 𝑦0 + 𝑘3 , 𝑧0 + 𝑙3 ) 𝑙4 = ℎ𝑓2 (𝑥0 + ℎ, 𝑦0 + 𝑘3 , 𝑧0 + 𝑙3 )
= 0.2𝑓1 (0.2,0.9800, −0.1958) = 0.2𝑓2 (0.2,0.9800, −0.1958)
= −0.03916 = −0.1905

1 1
𝛥𝑦 = 6 (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 ) =6 (0 + 2(−0.02) + 2(−0.01998) − 0.03916) =
−0.01985
1 1
𝛥𝑧 = 6 (𝑙1 + 2𝑙2 + 2𝑙3 + 𝑙4 ) =6 (−0.2 + 2(−0.1998) + 2(−0.1958) − 0.1905) =
−0.1970
𝒚(𝟎. 𝟐) = 𝒚𝟏 = 𝒚𝟎 + 𝜟𝒚 = 𝟏 − 𝟎. 𝟎𝟏𝟗𝟖𝟓 = 𝟎. 𝟗𝟖𝟎𝟐
𝒛(𝟎. 𝟐) = 𝒛𝟏 = 𝒛𝟎 + 𝜟𝒛 = 𝟎 − 𝟎. 𝟏𝟗𝟕𝟎 = 𝟎. 𝟏𝟗𝟕𝟎

𝑑2 𝑦 𝑑𝑦 𝑑𝑦
2. Given + 𝑥 𝑑𝑥 + 𝑦 = 0, 𝑦(0) = 1, (𝑑𝑥 ) = 0, find the value of 𝑦 for 𝑥 =
𝑑𝑥 2 𝑥=0
0.1, applying
Runge-Kutta method.

Answer
Put 𝑦 ′ = 𝑧 and 𝑦 ″ = 𝑧 ′ .
Then the given equation reduces to
𝑑𝑦 𝑑𝑧
= 𝑧, = −𝑥𝑧 − 𝑦
𝑑𝑥 𝑑𝑥
Given 𝑥0 = 0, 𝑦0 = 1, 𝑧0 = 𝑦0 ′ = 0, ℎ = 0.1
Let 𝑓1 (𝑥, 𝑦, 𝑧) = 𝑧
𝑓2 (𝑥, 𝑦, 𝑧) = −𝑥𝑧 − 𝑦

Using Runge-Kutta formula,

𝑘1 = ℎ𝑓1 (𝑥0 , 𝑦0 , 𝑧0 ) 𝑙1 = ℎ𝑓2 (𝑥0 , 𝑦0 , 𝑧0 )


= 0.1𝑓1 (0,1,0) = 0.1 × 𝑓2 (0,1,0)
=0 = −0.1
ℎ 𝑘1 𝑙1 ℎ 𝑘1 𝑙1
𝑘2 = ℎ𝑓1 (𝑥0 + , 𝑦0 + , 𝑧0 + ) 𝑙2 = ℎ𝑓2 (𝑥0 + , 𝑦0 + , 𝑧0 + )
2 2 2 2 2 2
= 0.1𝑓1 (0.05,1, −0.05) = 0.1𝑓2 (0.05,1, −0.05)
= −0.005 = −0.09975
ℎ 𝑘2 𝑙2 ℎ 𝑘2 𝑙2
𝑘3 = ℎ𝑓1 (𝑥0 + , 𝑦0 + , 𝑧0 + ) 𝑙3 = ℎ𝑓2 (𝑥0 + , 𝑦0 + , 𝑧0 + )
2 2 2 2 2 2
= 0.1𝑓1 (0.05,0.9975, −0.0499) = 0.1𝑓1 (0.05,0.9975, −0.0499)
= −0.00499 = −0.09950
𝑘4 = ℎ𝑓1 (𝑥0 + ℎ, 𝑦0 + 𝑘3 , 𝑧0 + 𝑙3 ) 𝑙4 = ℎ𝑓2 (𝑥0 + ℎ, 𝑦0 + 𝑘3 , 𝑧0 + 𝑙3 )
= 0.1𝑓1 (0.1,0.99511, −0.0995) = 0.1𝑓2 (0.1,0.99511, −0.0995)
= −0.00995 = −0.0985

1
𝒚(𝟎. 𝟏) = 𝒚𝟏 = 𝒚𝟎 + 𝜟𝒚 = 𝟏 + (𝑘 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6 1
1
=𝟏 +(0 + 2(−0.005) + 2(−0.00499) − 0.00995)
6
= 0.9950
PRACTICE PROBLEMS
1. Apply Runge-Kutta method of order 4 to find an approximate value of
𝑑𝑦
𝑦 for 𝑥 = 0.2 in steps of 0.1, if = 𝑥 + 𝑦 2 , given that 𝑦 = 1when𝑥 = 0.
𝑑𝑥
2. Given 𝑦 ″ + 𝑥𝑦 ′ + 𝑦 = 0, 𝑦(0) = 1, 𝑦 ′ (0) = 0, find the value of 𝑦(0.1) by
Runge-Kutta method.

You might also like