Numerical Solution of Ordinary DE

You might also like

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

Numerical solution of Ordinary Differential Equations 1

Numerical solution of Ordinary Differential Equations

A number of numerical methods are available for the solution of 1st order differential equations of the form

 f x , y , given yx 0   y0 i.e. y  y0 when x  x 0 


dy
dx

Working rule of some methods to find the value of y for some values of x, where

 f x , y , given yx 0   y0 i.e. y  y0 when x  x 0 .


dy
dx

1. Euler’s Method
yn  yn1  hf x 0  n  1h, yn1  , n  1, 2, 3,...
 dy   dy 
i.e. new y = old y + h  . as  f x , y  given
 dx   dx 
2. Modified Euler’s Method
new y = old y + hmean slope  , [mean slope is explained in the example 2.]

3. Runge-Kutta Method of order two.


1
y1  y 0  k, where k  k1  k 2 
2
and k1  hf x 0 , y 0 
k 2  hf x 0  h, y 0  k 1 

4. Fourth order Runge-Kutta Method.


k1  hf x 0 , y 0 
 1 1 
k 2  hf x 0  h, y 0  k1 
 2 2 
 1 1 
k 3  hf x 0  h, y 0  k 2 
 2 2 
k 4  hf x 0  h, y 0  k 3 
1
k k1  2k2  2k3  k4  .
6
Which gives the required approximate value y1  y 0  k

GH(Maths), APC Ray Polytechnic


Numerical solution of Ordinary Differential Equations 2

Example 1. Using Euler’s Method, find an approximate value of y corresponding to x = 1, given that
dy
 x  y and y  1 when x  0 .
dx

Solution : We take n = 10 so that h = 0.1 [ If n is not given, you have to take the value of n in such a way that h
is very small ].

The calculations are as follows :

x y dy
xy  dy 
old y + h  = new y
dx  dx 

0.0(given) 1.00(given) 0.0 + 1.00 = 1.00 1.00 + 0.1  1.00   1.10

0.1 1.10 0.1 + 1.10 = 1.20 1.10  0.1  1.20   1.22

0.2 1.22 0.2 + 1.22 = 1.42 1.22  0.1  1.42   1.36

0.3 1.36 0.3 + 1.36 = 1.66 1.36  0.1  1.66   1.53

0.4 1.53 0.4 + 1.53 = 1.93 1.53  0.1  1.93  1.72

0.5 1.72 0.5 + 1.72 = 2.22 1.72  0.1  2.22   1.94

0.6 1.94 0.6 + 1.94 = 2.54 1.94  0.1  2.54   2.19

0.7 2.19 0.7 + 2.19 = 2.89 2.19  0.1  2.89   2.48

0.8 2.48 0.8 + 2.48 = 3.28 2.48  0.1  3.28   2.81

0.9 2.81 0.9 + 2.81 = 3.71 2.81  0.1  3.71  3.18

1.0 3.18

 the required approximate value of y = 3.18 when x = 1.0.

dy y  x
Exercise : Given that  with initial condition y = 1 for x = 0. Find y for x =0.1 by Euler’s Method.
dx y  x

Ans. Y = 1.0928 for x =0.1 [ Hints- Take n = 5 i.e. h = 0.02 ].

GH(Maths), APC Ray Polytechnic


Numerical solution of Ordinary Differential Equations 3

Example 2. Using modified Euler’s Method, find an approximate value of y when x = 0.3, given that

dy
 x  y and y  1 when x  0 .
dx

Solution : Taking h = 0.1, calculations are as follows :

old y + h mean slope  = new y


dy
x xy Mean slope
dx
0 0 + 1 = 1.00 ----- 1.00  0.1  1.00   1.10

0.1 0.1 + 1.1 = 1.2


1
1.0  1.2  1.1 1.00  0.1  1.1  1.11
2
0.1 0.1 + 1.11 = 1.21
1
1.0  1.21  1.105 1.00  0.1  1.105   1.1105
2
0.1 0.1 + 1.1105 = 1.2105
1
1.0  1.2105   1.1052 1.00  0.1  1.1052   1.1105
2
0.1 0.1 + 1.1105 = 1.2105 ----- 1.1105  0.1  1.2105   1.2316

0.2 0.2 + 1.2316 = 1.4316


1
1.2105  1.4316   1.3211 1.1105  0.1  1.3211   1.2426
2
0.2 0.2 + 1.2426 = 1.4426
1
1.2105  1.4426   1.3266 1.1105  0.1  1.3266   1.2432
2
0.2 0.2 + 1.2432 = 1.4432
1
1.2105  1.4432   1.3268 1.1105  0.1  1.3268   1.2432
2
0.2 0.2 + 1.2432 = 1.4432 ----- 1.2432  0.1  1.4432   1.3875

0.3 0.3 + 1.3875 = 1.6875


1
1.4432  1.6875   1.5654 1.2432  0.1  1.5654   1.3997
2
0.3 0.3 + 1.3997 = 1.6997
1
1.4432  1.6997   1.5715 1.2432  0.1  1.5715   1.4003
2
0.3 0.3 + 1.4003 = 1.7003
1
1.4432  1.7003   1.5718 1.2432  0.1  1.5718   1.4004
2
0.3 0.3 + 1.4004 = 1.7004
1
1.4432  1.7004   1.5718 1.2432  0.1  1.5718   1.4004
2

 y(0.3) = 1.404(approx.) Ans.

Note : Modified Euler’s Method gives us better result(less error) than Euler’s Method.

Exercise : Using modified Euler’s Method, find an approximate value of y(0.4) [ i.e. y when x = 0.4], given that

 e  y , y0 0 i.e. y  0 when x  0 .


dy x
dx
Ans : y(0.4) = 0.6031. [ Hints – Take h = 0.2 ]

GH(Maths), APC Ray Polytechnic


Numerical solution of Ordinary Differential Equations 4

Example 3. Apply Runge-Kutta method of fourth order to find an approximate value of y for x = 0.2 taking
dy
steps of 0.1, if  x  y2 , given that y = 1 when x = 0.
dx

Solution : Here, h = 0.1

Step 1. x0 = 0, y0 = 1, h = 0.1

k1  hf x 0 , y 0  = 0.1  f 0, 1 = 0.1000


 1 1 
k 2  hf x 0  h, y 0  k1  = 0.1  f 0.05, 1.05 = 0.1152
 2 2 
 1 1 
k 3  hf x 0  h, y 0  k 2  = 0.1  f 0.05, 1.0576  = 0.1168
 2 2 
k 4  hf x 0  h, y 0  k 3  = 0.1  f 0.1, 1.1168  = 0.1347
1 1
k k1  2k2  2k3  k4  = 0.1000  2  0.1152  2  0.1168  0.1347  = 0.1165
6 6

 y0.1  y 0  k  1  0.1165  1.1165 .

Step 2. x1 = x0+h = 0.1, y1 = 1.1165, h = 0.1

k1  hf x1 , y1  = 0.1  f 0.1, 1.1165  = 0.1347


 1 1 
k2  hf x1  h, y1  k1  = 0.1  f 0.15, 1.1838  = 0.1551
 2 2 
 1 1 
k3  hf x1  h, y1  k2  = 0.1  f 0.15, 1.194  = 0.1576
 2 2 
k 4  hf x1  h, y1  k3  = 0.2  f 0.1, 1.1576  = 0.1823
1 1
k k1  2k2  2k3  k4  = 0.1347  2  0.1551  2  0.1576  0.1823  = 0.1571
6 6

 y0.2  y1  k  1.1165  0.1571  1.2736 Ans.

Exercise :
dy y2  x2
1. Apply Runge-Kutta method of fourth order solve  with y0   1 at x = 0.2, 0.4
dx y2  x2
[Ans- y(0.2) = 1.196 and y(0.4) = 1.3752.]
dy 2xy  ex
2. Using Runge-Kutta method of fourth order solve for y at x= 1.2 and 1.4 from  , given x0 = 1, y0
dx x 2  xex
=0. [Ans- y(1.2) = 0.1402 and y(1.4) = 0.2705.]

[Note : If in the question order is not given, you should follow Runge-Kutta method of fourth order.]

GH(Maths), APC Ray Polytechnic

You might also like