Numerical Methods for ODE
Numerical Methods for ODE
There exists large number of ordinary differential equations, whose solution cannot be obtained
by the known analytical methods. In such cases, we use numerical methods to get an
approximate solution of a given differential equation with given initial condition.
Consider an ordinary differential equation of first order and first degree of the form
dy
f x, y with the initial condition y x0 y0 which is called initial value problem.
dx
Euler’s Method
dy
Consider the first order differential equation f x, y
dx
With the initial condition y x0 y0
The approximate value of y at x x1 is denoted by y1
y1 y0 hf x0 , y0
The approximate value of y at x x2 is denoted by y2
y2 y1 hf x1 , y1
In general, we obtain a recursive relation as
yn 1 yn hf xn , yn n = 0, 1, 2, ………
This is known as Euler’s algorithm
dy
Using Euler's method, solve for y at x 0.4, from e , y 0 0
x2
dx
taking step size h 0.1
dy
Sol: Given that e if y 0 0 and h 0.1
x2
dx
dy
f x, y e with initial condition y 0 0
x2
dx
The Euler's method is yn 1 yn hf xn , yn
i y1 y0 hf x0 , y0 0 0.1 f 0, 0 0 0.11 0.1
y1 y 0.1 0.1
ii y2 y1 hf x1 , y1 0.1 0.1 f 0.1, 0.1 0.1 0.11.0100 0.2
y2 y 0.2 0.2
iii y3 y2 hf x2 , y2 0.2 0.1 f 0.2, 0.2 0.2 0.11.0408 0.3
y3 y 0.3 0.3
iv y4 y3 hf x3 , y3 0.3 0.1 f 0.3, 0.3 0.3 0.11.0941 0.41
y4 y 0.4 0.41
dy y x
Problem: Given with initial condition y 0 1, find y 0.1 by Euler's
dx y x
method, taking step size h 0.02
yx
Sol: Given f x, y
yx
First we divide the x values into sub intervals using h
x0 0, x1 0.02, x2 0.04, x3 0.06, x4 0.08, x5 0.1
y0 0, y1 , y2 , y3 , y4 , y5 0.1
y1 y0 hf x0 , y0 1 0.02 f 0,1 1 0.02 1 1.02
y1 y 0.02 1.02
y2 y1 hf x1 , y1 1.02 0.02 f 0.02,1.02 1.02 0.02 0.9615 1.039
y2 y 0.04 1.039
y3 y2 hf x2 , y2 1.039 0.02 f 0.04,1.039 1.039 0.02 0.9258 1.057
y3 y 0.06 1.057
y4 y3 hf x3 , y3 1.057 0.02 f 0.06,1.057 1.057 0.02 0.8925 1.075
y4 y 0.08 1.075
y5 y4 hf x4 , y4 1.075 0.02 f 0.08,1.075 1.075 0.02 0.8615 1.092
y5 y 0.1 1.092
Modified Euler’s method
dy
Consider the first order differential equation f x, y
dx
with the initial condition y x0 y0
The approximate value of y at x x1 is denoted by y1
y1(0) y0 hf ( x0 , y0 )
h
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1( 0) ) ,
(1)
2
h
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1(1) ) , ….,
( 2)
2
( K 1) h
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1( K ) )
2
To get y2 we use the above procedure again.
Using modified Euler’s method find y 0.1 and y 0.2
dy
given that x2 y, y 0 1 , taking step size h = 0.1
dx
dy
Sol. Here x2 y, y 0 1 and h = 0.1
dx
To find y1 i .e y(0.1)
Using Modified Euler’s formula
y1(0) y0 hf ( x0 , y0 ) 1 0.1 1 0.9
The First Approximation to y1
h 0.1
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1 ) 1
(1) ( 0)
(1 f (0.1,0.89)) 0.995
2 2
Second Approximation to y1
h 0.1
y1( 2) y0 ( f ( x0 , y0 ) f ( x1 , y1(1) ) = 1+ ((1 f (0.1,0.995)) 0.90075
2 2
Third Approximation to y1
h 0.1
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1 ) = 1+
( 3) ( 2)
((1 f (0.1,0.90075 )) 0.90546
2 2
Fourth Approximation to y1
h 0.1
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1 ) 1
( 4) ( 3)
((1 f (0.1,0.90546 )) 0.90523
2 2
Fifth Approximation to y1
h 0.1
y1 y0 ( f ( x0 , y0 ) f ( x1 , y1 ) 1
(5) (4)
((1 f (0.1, 0.90523))
2 2
0.1
1 (1 0.89523) 0.90523
2
Since y1( 4) , y1(5) are same, therefore y 0.1 = 0.90523
To find y2 i.e y(0.2)
Using Modified Euler’s formula
y2(0) y1 h( f ( x1 , y1 ) = 0.90523 + 0.1 f(0.1, 0.90523) = 0.90523+0.1(-0.8952)=0.8157
The First Approximation to y2
h 0.1
y2(1) y1 ( f ( x1 , y1 ) f ( x2 , y2(0) ) 0.90523 (0.8952 f (0.2, 0.8157))
2 2
0.1
0.90523 (0.8952 (0.04 0.8157)) 0.90523 0.0835 0.8217
2
The Second Approximation to y2
h 0.1
y2(2) y1 ( f ( x1 , y1 ) f ( x2 , y2(1) ) 0.90523 (0.8952 f (0.2, 0.8217))
2 2
0.90523 0.08385 0.8214
The Third Approximation to y2
h 0.1
y2(3) y1 ( f ( x1 , y1 ) f ( x2 , y2(2) ) 0.90523 ( 0.8952 f (0.2, 0.8214))
2 2
0.90532 0.08383 0.8214
Since y2( 2) , y2(3) are same, therefore y 0.2 = 0.8214
Runge - Kutta method of fourth order
dy
Consider the first order differential equation f x, y
dx
with the initial condition y x0 y0
The Runge - Kutta fourth order method is
k1 hf x0 , y0
h k
k2 hf x0 , y0 1
2 2
h k
k3 hf x0 , y0 2
2 2
k4 hf x0 h, y0 k3
1
Now k k1 2k2 2k3 k4
6
Then we can calculate y1 y0 k
Using Runge -Kutta method of order four, find y 0.2
dy
from f x, y y x , y 0 2, taking step size h 0.1
dx
dy
Sol: Given f x, y y x , x0 0, y0 2, h 0.1
dx
k1 hf x0 , y0 0.1 f 0, 2 0.1 2 0 0.2
h k1 0.1 0.2
k2 hf x0 , y0 0.1 f 0 ,2
2 2 2 2
0.1 f 0.05, 2.1 0.1 2.1 0.05 0.205
h k2 0.1 0.205
k3 hf x0 , y0 0.1 f 0 ,2
2 2 2 2
0.1 f 0.05, 2.1025 0.1 2.1025 0.05 0.20525
k4 hf x0 h, y0 k3 0.1 f 0 0.1, 2 0.20525
0.1 f 0.1, 2.20525 0.1 2.20525 0.1 0.210525
1
then k k1 2k2 2k3 k4
6
1
0.2 2 0.205 2 0.20525 0.210525 0.11607
6
and y1 y0 k 2 0.11607 2.11607
ii Now x1 0.1, y1 2.11607, h 0.1
k1 hf x1 , y1 0.1 f 0.1, 2.11607
0.1 2.11607 0.1 0.201607
h k1 0.2 0.201607
k2 hf x1 , y1 0.1 f 0.1 , 2.11607
2 2 2 2
0.1 f 0.2, 2.168735 0.20169
h k2 0.2 0.20169
k3 hf x1 , y1 0.1 f 0.1 , 2.11607
2 2 2 2
0.1 f 0.2, 2.21691 0.20169
k4 hf x1 h, y1 k3 0.1 f 0.1 0.1, 2.11607 0.20169
0.1 f 0.2, 2.21692
0.20169
1
then k k1 2k2 2k3 k4
6
1
0.201607 2 0.20169 2 0.20169 0.20169
6
0.20168
and y2 y1 k 2.11607 0.20168 2.31775