Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views30 pages

Numerical Solutions of Ordinary Differential Equations

This document provides a comprehensive overview of numerical solutions for ordinary differential equations (ODEs), focusing on methods such as Euler's method and the Runge-Kutta methods of second and fourth order. It outlines learning outcomes, basic concepts, and practical examples to illustrate the application of these numerical techniques. The content is designed for students and practitioners in the field of numerical analysis and differential equations.

Uploaded by

Karan Saw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views30 pages

Numerical Solutions of Ordinary Differential Equations

This document provides a comprehensive overview of numerical solutions for ordinary differential equations (ODEs), focusing on methods such as Euler's method and the Runge-Kutta methods of second and fourth order. It outlines learning outcomes, basic concepts, and practical examples to illustrate the application of these numerical techniques. The content is designed for students and practitioners in the field of numerical analysis and differential equations.

Uploaded by

Karan Saw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Numerical Solutions of Ordinary Differential Equations

Lesson: Numerical Solutions of Ordinary Differential Equations

Course Developer: Dr. Sada Nand Prasad

College/Department: A.N.D. College (D.U.)

Institute of Lifelong Learning, University of Delhi Pg. 1


Numerical Solutions of Ordinary Differential Equations

Table of Contents:

• Chapter : Numerical Solutions of Ordinary Differential


Equations
• 1. Learning Outcomes
• 2. Introduction
• 3. Basic Concepts
• 4. Euler’s Method
• 5. Runge-Kutta Method
• 5.1. Runge-Kutta Method of second order
• 5.2. Runge-Kutta Methods of fourth order
• Summary
• Exercises
• Glossary
• References/ Further Reading

1. Learning Outcomes:
After studying this chapter, you should be able to
➢ identify the initial value problem for the first order ordinary
differential equations;
➢ obtain the solution or the initial value problems by using Euler's
method;
➢ obtain the solution of IVPs using Runge-Kutta methods of second
and fourth order;
➢ extrapolate the approximate value of the solutions obtained by the
Runge-Kutta methods of second and fourth order;

Institute of Lifelong Learning, University of Delhi Pg. 2


Numerical Solutions of Ordinary Differential Equations

2. Introduction:
Solving differential equations, both ordinary and partial, is one of the
most useful and important application of numerical analysis. There are
mainly two common problems we face in finding the numerical solution of
a differential equation. The first one is: When one finds a numerical
solution is sufficiently close to the exact solution? The second problem is
the instability of numerical solution. The actual solution to the problem of
interest is stable, but the errors incurred in the numerical solution are
magnified in such a way that the numerical solution is obviously
incompatible with the actual solution. A numerical method that gives
accurate results and is stable with the least amount of computation time
often requires that it be started with a somewhat less accurate method
and then continued with a more accurate technique. There are many
starting techniques and methods that are used to continue a solution. In
this chapter we shall introduce two such methods namely, Euler's method
and Runge-Kutta Method of second order and fourth order to obtain
numerical solution of ordinary differential equations (ODEs). Initially we
shall focus on solving the first order equations, since, every nth–order
equation is equivalent to a system of n first–order equations. To begin
with, we shall recall few basic concepts from the theory of differential
equations which we shall be referring quite often.

3. Basic Concepts:
In this section, we shall start with few definitions from differential
equations and define some concepts which are involved in the numerical
solution of differential equations.
Definition: An equation relating an unknown function (dependent
variables) to its various derivatives with respect to known functions
(independent variables) is called a differential equation, thus
d2 f
2
+ 2 x f = ex (1)
dx

Institute of Lifelong Learning, University of Delhi Pg. 3


Numerical Solutions of Ordinary Differential Equations

 2u  2u
+ =0 (2)
x 2 y 2
are examples of differential equations.

Value Additions:
Differential equations involving derivatives w.r.t. a single independent
variable are called ordinary differential equations (ODEs) whereas, A
partial differential equations (PDEs) contains partial derivatives w.r.t.
more than one independent variable. Eqn. (1) is an ODE, while Eqn. (2)
is a PDE.

Definition: The order of a differential equation is the order of the


highest derivative occurring in the equation and its degree is the highest
exponent of the highest order derivative after the equation has been
rationalised. The order and degree of the equation
4
 d 3u  d 2u
 3 + 2 x 2
− sin u = e x (3)
 dx  dx

is 3 and 4 respectively.
The general solution of an nth order linear equation is a family of
solutions containing n arbitrary constants. In order to determine these
arbitrary constants, n conditions are required. If these conditions are
given at one point, then these conditions are known as initial conditions
and the differential equation together with the initial conditions is called
an initial value problem (IVP).
If the n conditions are prescribed at more than one point then these
conditions are known as boundary conditions. The differential equation
together with the boundary condition is known as a boundary value
problem (BVP).

Institute of Lifelong Learning, University of Delhi Pg. 4


Numerical Solutions of Ordinary Differential Equations

We will need to study numerical methods for the solution of the first order
IVP
y ' = f ( y, t ) , y (t 0 ) = y0 …(4)

Starting with the initial values, the solution are hence constructed step by
step through a series of equal intervals in the independent variables so
that as soon as the solution has been carried to x = x i; the next step will
be to evaluate the change in the solution through the interval Δx = h of x i
to xi + 1.

Let us take the interval  t 0 ,b over which the solution of the IVP (4) is

required. Sub-dividing the interval  t 0 ,b  into n sub-intervals using a step


size
t −t 
h =  n 0  , wheretn = b
 n 
We can then write tk = t0 + kh, k = 0,1,. . . . .n . A numerical method for the

solution of the IVP (4), will produce approximate values yk , at the grid

points tk .
Let us now discuss how to construct numerical methods and related basic
concepts with reference to a simple ODE
dy
=  y, y (t 0 ) = y 0 , t a, b  (5)
dt
Let us define the grid point by
tk = t0 + kh, k = 0,1,. . . . .n , where t0 = a and t0 + n h = b

Separating the variables and integrating, we find that the exact solution
of Eqn. (5) is
y ( t ) = y ( t0 ) e
 ( t − t0 )
(6)

To get a relationship that connects two successive solution values, we put


t = tn and t = tn +1 in Eqn. (6). Thus we get,

Institute of Lifelong Learning, University of Delhi Pg. 5


Numerical Solutions of Ordinary Differential Equations

y ( t n ) = y ( t0 ) e
 ( tn − t0 )

and
 ( tn + 1 − t0 )
y ( t n +1 ) = y ( t 0 ) e

Dividing, we get,
y ( t n +1 ) e  tn + 1  (t − t )
=  tn = e n + 1 n
y ( tn ) e

Hence we have,
y ( t n +1 ) = e  h y ( t n ) (7)

Eqn. (7) gives the required relation between y ( tn ) and y ( tn +1 ) .

Putting n = 0, 1, 2, . . . . . we can find y ( t1 ) , y ( t2 ) , y ( t3 ) ..... from the given

value y ( t0 ) .

We can get a numerical method by approximating e h in Eqn. (7). We


may use the following polynomial approximations.

e h =1 +  h + o  h ( 2
) (8)

e h =1 +  h +
 2 h2
2
+o  h ( 3
) (9)

e h =1 +  h + +
 2 h2
2
+
 3 h3
6
(
+o  h
4
) (10)

and so on.
Now retain (p+l) terms in the expansion of e h and denote the

approximation e h by E (  h ) . The numerical method for obtaining the

approximate values tn , of y ( tn ) can then be written as

yn +1 = E (  h ) yn , n = 0,1, 2,3,....... (11)

4. Euler’s Method:
Let us consider the first-order equation which can put in the form
y = f ( y, t ) (12)

dy
where y = . If yi and yi at ti are known, then Eq. (12) can be used to
dt

give yi +1 and yi +1 at ti +1 .
Institute of Lifelong Learning, University of Delhi Pg. 6
Numerical Solutions of Ordinary Differential Equations

Euler’s method results from approximating the derivative


dy y
= lim (13)
dt t → 0 t
By the difference equation
y  y t (14)
Or, in the difference notation

yi +1 = h y i (15)

where h = t = ti +1 − ti , is the step size.

Example 1: Use Euler’s method to Solve the IVP


dy
=1 − 2 y t , y (0.2) = 0.1948. Find y (0.2) with h = 0.2 .
dt
Solutions: In Euler’s method we must have the first derivative at each

point; it is given by yi =1−2yt


i i

The solution is approximated at each point by


yi +1 = yi + h yi = yi + h (1 − 2 yi ti )
y (0.4) = 0.1948 + (0.2) (1 - 2 x 0.2 x 0.1948)
= 0.379216.

Example 2: Solve the IVP y ' = t + y, y ( 0 ) = 1, by Euler's method using

h = 0.1. Find the exact error, if the exact value is y (1) = 3.436564.

Solution: Euler's method is given by yi +1 = yi + h yi

For our problem, we have yi +1 = yi + h ( ti + yi ) = (1+ h ) yi + hti

Starting the iteration with h = 0.1, y ( 0 ) = 1 , we get,

y1 = (1 + 0.1) 1 + ( 0.1) ( 0 ) = 1.1

y2 = (1.1)(1.1) + ( 0.1)( 0.1) = 1.22,

y3 = (1.1)(1.22 ) + ( 0.1)( 0.2 ) = 1.362

y4 = (1.1)(1.362 ) + ( 0.1)( 0.3) = 1.5282,

y5 = (1.1)(1.5282 ) + ( 0.1)( 0.4 ) = 1.72102,

y6 = (1.1)(1.72102 ) + ( 0.1)( 0.5) = 1.943122,


Institute of Lifelong Learning, University of Delhi Pg. 7
Numerical Solutions of Ordinary Differential Equations

y7 = (1.1)(1.943122 ) + ( 0.1)( 0.6 ) = 2.197434,

y8 = (1.1)( 2.197434 ) + ( 0.1)( 0.7 ) = 2.487178,

y9 = (1.1)( 2.487178) + ( 0.1)( 0.8) = 2.815895

y10 = (1.1)( 2.815895) + ( 0.1)( 0.9 ) = 3.187485 = y (1)

actual error = y (1) − y10 = 3.436564 − 3.187485 = 0.2491.

dy
Example 3: Solve the IVP 3 + 5 y 2 = sin t , y (0.3) = 5 by Euler's method using
dt
h = 0.3. Find the value of y ( 0.9 ) .

Solution: First rewrite the differential equation in the proper form.

= f ( y, t ) = ( sin t − 5 y 2 ) , y (0.3) = 5
dy 1
dt 3
Euler’s method is given by yi +1 = yi + h f ( yi , ti )

where
h = 0.3, for i = 0, t0 = 0.3, y0 = 5,

y1 = y0 + h f ( y0 , t0 ) = 5 + 0.3
1
3
( )
sin ( 0.3) − 5 ( 5 ) = − 7.4704
2

Y1 is the approximate value of y at


t = t1 = t0 + h = 0.3 + 0.3 = 0.6, for i =1, t1 = 0.6, y1 = − 7.4704,

y2 = y1 + h f ( y1 , t1 ) = − 7.4704 + 0.3
1
3
( )
sin ( 0.6 ) − 5 ( −7.4704 ) = − 35.318
2

Y2 is the approximate value of y at


t = t2 = t2 + h = 0.6 + 0.3 = 0.9,
y2 = y ( 0.9 ) = − 35.318

dy 4 t
Example 4: Solve the IVP = , y (0) =1 by Euler's method using h = 0.5.
dt y

Find the value of y (1) .

Solution: First rewrite the differential equation in the proper form.


dy 4t
= f ( y, t ) = , y (0) =1
dt y
Euler’s method is given by yi +1 = yi + h f ( yi , ti )

where
Institute of Lifelong Learning, University of Delhi Pg. 8
Numerical Solutions of Ordinary Differential Equations

h = 0.5, for i = 0, t0 = 0, y0 =1,


4 0
y1 = y0 + h f ( y0 , t0 ) =1 + 0.5  =0
1
Y1 is the approximate value of y at
t = t1 = t0 + h = 0 + 0.5 = 0.5, for i =1, t1 = 0.5, y1 =1,
4  0.5
y2 = y1 + h f ( y1 , t1 ) =1 + 0.5  =2
1
Y2 is the approximate value of y at
t = t2 = t2 + h = 0.5 + 0.5 =1,
y2 = y (1) = 2

Value Addition:
Euler’s method is simpler to use since we do not have to compute higher
derivatives at each point. It could also be used to solve higher order
equations.

5. Runge-Kutta Methods:
In order to produce accurate results using Taylor’s method, derivatives of
higher order must be evaluated. This may be difficult, or the higher-order
derivatives may be inaccurate. Methods that require only the first-order
derivative and give results with the same order of truncation error as
Taylor’s method maintain the higher-order derivatives are called the
Runge-Kutta method. Estimates of the derivative must be made at points

within each interval ti t ti +1 . The prescribed first-order equation is used to


provide the derivative at the interior points. The Runge-Kutta method of
second-order will be developed and the Runge-Kutta method of fourth-
order will simply be presented with no development.

Value Addition:
Since Euler's method is of first, it requires h to be very small to attain the
desired accuracy. Hence, very often, the number of steps to be carried

Institute of Lifelong Learning, University of Delhi Pg. 9


Numerical Solutions of Ordinary Differential Equations

out becomes very large. In such cases, we need higher order methods
like Runge-Kutta to obtain the required accuracy in a limited number of
steps.

5.1. Runge-Kutta Method of second order

Let us consider the first-order equation y= f ( y,t) . All Runge-Kutta

methods utilize the approximation

yi +1 = h i , (16)

where i is an approximation to the slope in the interval ti t ti +1 .

Certainly, if we used i = fi , the approximation for yi +1 would be too large

for the curve in Figure 1; and, if we used i = fi +1, the approximation would

be too small. Hence, the correct i needed to give the exact yi +1 lies in the
interval fi    fi +1.

Slope = fi

Slope = fi +1

yi =f (yi,ti )
ti h ti + 1

yi y
Figure 1. Curve showing approximations to yi +1i +,1 using slopes fi and fi +1

Institute of Lifelong Learning, University of Delhi Pg. 10


Numerical Solutions of Ordinary Differential Equations

The trick is to find a technique that will give a good approximation to the

correct slope i . Let us assume that

i = a i + bi (17)
where i = f ( yi , ti ) (18)
i = f ( yi + q h i , ti + p h ) (19)

The quantities a, b, p, and q are constant to be established later.

A good approximation for i is found by expanding in a Taylor series,


neglecting higher-order terms:

f f
i = f ( yi , ti ) +( yi , ti ) y + ( yi , ti ) t + o (h 2 )
y t
f f
= fi + q h fi ( yi , ti ) + p h ( yi , ti ) t + o (h 2 ) (20)
y t

Where we have used y = qhfi and t = ph, as required by eqn. (19). Eqn.

(16) then becomes, using i = fi ,

yi +1 = yi + h i = yi + h ( a i + bi )
 f f 
= yi + h ( a fi + b fi ) + h 2 b q fi ( yi , ti ) + b p f i ( yi , ti )  + o(h 3 ), (21)
 y t 

where we have substituted for i and i from eqn. (18) and (20),

respectively. Expand yi in Taylor series with second order, so that

h2
yi +1 = yi + h yi + yi
2
h2
= yi + h f ( yi , ti ) + f ( yi , ti ) (22)
2

Now, using the chain rule,

f y f t f f f f
f= + =y + = f + (23)
y t t t y t y t

Thus, we have
Institute of Lifelong Learning, University of Delhi Pg. 11
Numerical Solutions of Ordinary Differential Equations

h2  f f 
yi +1 = yi + h f ( yi , ti ) +  fi y ( yi , ti ) + t ( yi , ti )  (24)
2  

Comparing this with eqn. (21), we find that (equating terms in like
powers of h)

a + b = 1, b q = ½, bp=½ (25)

These three equations contain four unknowns; hence one of them is


arbitrary. It is compulsory to choose b = ½ or b = 1. For b = ½, we have

a = ½, q = 1 and p = 1. Then our approximation for yi +1 from eqn. (21)


becomes

yi +1 = yi + h ( a i + bi )
h
= yi +  f ( yi , ti ) + f ( yi + h f i , ti + h )  (26)
2

For b = 1, we have a = 0, q = ½, and p = ½, these results

 h h
yi +1 = yi + hi = yi + h f  yi + fi , ti +  (27)
 2 2

Knowing yi , ti and yi = fi we can now calculate yi +1 with the same accuracy

obtained using Taylor’s method that required us to know yi .

Value Addition:

The different R-K methods are of second order are given by

(1) Optimal R-K method:

1
yi +1 = yi + i + 3i  (28)
4
where
i = h f ( yi , ti )
 2 2h 
i = h f  yi + i , ti + 
 3 3 

Institute of Lifelong Learning, University of Delhi Pg. 12


Numerical Solutions of Ordinary Differential Equations

(2) Improved tangent method:

yi +1 = yi +i (29)
where
i = h f ( yi , ti )
  h
i = h f  yi + i , ti + 
 2 2

This method is also known as modified Euler's method.

(3) Heun's method:

1
yi +1 = yi + (  i + i ) (30)
2
where
i = h f ( yi , ti )
i = h f ( yi + i , ti + h )

This method is also known as the Euler-Cauchy method.

Example 5: Solve the IVP y ' =1+ y 2 , y (0) = 0 and find y ( 0.4 ) with h = 0.2 using

the following R-K methods of second order

a) Optimal R-K method


b) Improved tangent method
c) Heun's method

Compare the results with the exact solution y(t)=tant, and find the errors.

Solutions: a) Optimal Runge-Kutta, method:

0 = h f ( y0 , t0 ) = h (1 + y0 2 ) = 0.2 (1 + 0 ) = 0.2
2 0 2h    2 0     2  0.2  
2 2

0 = h f  y0 + , t0 + = h 1 + y0 +  = 0.2 1 +  0 +  
 3 3    3     3  
= 0.2035556

Thus,
Institute of Lifelong Learning, University of Delhi Pg. 13
Numerical Solutions of Ordinary Differential Equations

1 1
y 1 = y ( 0.2 ) = y0 + 0 + 30  = 0 +  0.2 + 3 0.2035556  = 0.2026667
4 4
To calculate y2 , we need ,

1 = h f ( y1 , t1 ) = h (1 + y12 ) = 0.2 1 + (0.2026667)2  = 0.2082148


 2 2h 
1 = h f  y1 + 1 , t1 + 
 3 3 
  2 1  
2

= h 1 +  y1 +  
  3  
  2  0.2082148  
2

= 0.2 1 +  0.2026667 +  
  3  
= 0.223321245

Thus,
y 2 = y ( 0.4 )
1 1
= y1 + 1 + 31  = 0.2026667 +  0.2082148 + 3 0.223321245 
4 4
= 0.422211334

b) Improved tangent method is

 0 = h f ( y0 , t0 ) = h (1 + y0 2 ) = 0.2 (1 + 0 ) = 0.2,
0 h   0     0.2  
2 2

0 = h f  y0 + , t0 +  = h 1 +  y0 +   = 0.2 1 +  0 +   = 0.202
 2 2    2     2  
y1 = y ( 0.2 ) = y0 +0 = 0 + 0.202 = 0.202
1 = h f ( y1 , t1 ) = h (1 + y12 ) = 0.2 1 + (0.202) 2  = 0.2081608,
 h        0.2081608  
2 2

1 = h f  y1 + 1 , t1 +  = h 1 +  y1 + 1   = 0.2 1 +  0.202 +  
 2 2    2     2  
= 0.21873704
y2 = y ( 0.4 ) = y1 +1 = 0.202 + 0.21873704 = 0.42073704

c) Heun's method :

0 = h f ( y0 , t0 ) = h (1 + y0 2 ) = 0.2 (1 + 0 ) = 0.2
0 = h f ( y0 + 0 , t0 + h ) = h 1 + ( y0 + 0 )  = 0.2 1 + ( 0 + 0.2 )  = 0.208
2 2
   
1 1
y1 = y ( 0.2 ) = y0 + (0 +0 ) = 0 + ( 0.2 + 0.208) = 0.204
2 2

Institute of Lifelong Learning, University of Delhi Pg. 14


Numerical Solutions of Ordinary Differential Equations

1 = h f ( y1 , t1 ) = h (1 + y12 ) = 0.2 1 + ( 0.204 )  = 0.2083232


2
 

1 = h f ( y1 + 1 , t1 + h ) = h 1 + ( y1 + 1 )  = 0.2 1 + ( 0.204 + 0.2083232 ) 


2 2
   
= 0.2340020843
1 1
y2 = y ( 0.4 ) = y1 + (1 +1 ) = 0.204 + ( 0.2083232 + 0.2340020843)
2 2
= 0.4251626422

Now the exact solution is y(t) = tan t


Exact y(0.4) = 0.422793219
−3
Error in Optimal R-K method = 0.58210
−2
Error in Improved tangent method= 0.20510

Error in Heun's method = 0.236 10−2


Example 6: Solve the IVP y ' = t 2 + y 2 , y (0) =1 and find y ( 0.2 ) with h = 0.1

using the following R-K methods of second order

a) Optimal R-K method


b) Improved tangent method
c) Heun's method

Solution: a) Optimal Runge-Kutta, method:

0 = h f ( y0 , t0 ) = h ( t0 2 + y0 2 ) = 0.1( 0 + 1) = 0.1
2 2 h   2  
2 2
 2h  
0 = h f  y0 + 0 , t0 +  = h  t0 +  +  y0 + 0  
 3 3   3   3  
 2  0.1   2  0.1  
2 2

= 0.1  0 +  + 1 +   = 0.11422222
 3   3  

Thus,
1 1
y 1 = y ( 0.1) = y0 + 0 + 30  =1+  0.1+ 3 0.11422222  = 1.11066667
4 4
To calculate y2 , we need,

1 = h f ( y1 , t1 ) = h ( t12 + y12 ) = 0.1 (0.1) 2 + (1.11066667) 2  = 0.12435805

Institute of Lifelong Learning, University of Delhi Pg. 15


Numerical Solutions of Ordinary Differential Equations

2 2 h   2  
2 2
 2h  
1 = h f  y1 + 1 , t1 +  = h  t1 +  +  y1 + 1  
 3 3   3   3  

 2  0.1  
2
2  0.12435805  
2

= 0.1  0.1 +  + 1.11066667 +   = 0.1452392


 3   3  

Thus,
1 1
y 2 = y ( 0.2 ) = y1 + 1 + 31  =1.11066667 +  0.12435805 + 3 0.1452392 
4 4
= 1.25068558

b) Improved tangent method is


0 = h f ( y0 , t0 ) = h (t02 + y02 ) = 0.1(1+ 0) = 0.1,
0 h   0  
2 2
 h 
0 = h f  y0 + , t0 +  = h  t0 +  +  y0 +  
 2 2   2  2  
  0.1 
2

= 0.10.0025+ 1+   = 0.1105


  2  
y1 = y (0.1) = y0 +0 =1+ 0.1105=1.1105
1 = h f ( y1, t1 ) = h (t12 + y12 ) = 0.10.01+ (1.1105)2  = 0.12432,
1 h   1  
2 2
 h 
1 = h f  y1 + , t1 +  = h  t1 +  +  y1 +  
 2 2   2  2  
 2
0.1  0.12432  
2

= 0.1  0.1+  + 1.1105+   = 0.13976


  2   2  
y2 = y (0.2) = y1 +1 =1.1105+ 0.13976 =1.25026

c) Heun's method :
0 = h f ( y0 , t0 ) = h ( t0 2 + y0 2 ) = 0.1( 0 + 1) = 0.1
0 = h f ( y0 + 0 , t0 + h ) = h ( t0 + h ) + ( y0 + 0 )  = 0.1 0.01+ 1.21 = 0.122
2 2
 
1 1
y1 = y ( 0.1) = y0 + (0 +0 ) =1 + ( 0.1+ 0.122 ) =1.111
2 2
1 = h f ( y1 , t1 ) = h ( t12 + y12 ) = 0.1 0.01 + (1.111)  = 0.1244321
2
 

1 = h f ( y1 + 1 , t1 + h ) = h ( t1 + h ) + ( y1 + 1 ) 
2 2
 
= 0.1 0.04 + 1.52629247  = 0.15662925

Institute of Lifelong Learning, University of Delhi Pg. 16


Numerical Solutions of Ordinary Differential Equations

1 1
y2 = y ( 0.2 ) = y1 + (1 +1 ) =1.111+ ( 0.1244321+ 0.15662925) =1.25153068
2 2
Example 7: Solve the IVP y ' = − t y 2 , y (2) =1 and find y ( 2.2 ) with h = 0.1 using

the following R-K methods of second order

a) Optimal R-K method


b) Improved tangent method
c) Heun's method
Solutions: a) Optimal Runge-Kutta, method:
0 = h f ( y0 , t0 ) = h(−t0 y02 ) =0.1(− 2) = − 0.2
20 2h    2  
2
 2h 
0 = h f  y0 + , t0 +  = h − t0 +  y0 + 0  
 3 3    3  3  
  0.2  20.2 2 
=0.1− 2 + 1−   =− 0.15522963
  3  3  
1 1
Thus, y1 = y (2.1) = y0 +0 +30 =1+  −0.2−30.15522963 = 0.83357778
4 4
Tocalculate y2 , weneed,
1 = h f ( y1, t1 ) = h(−t1 y12 ) =0.1− 2.1(0.83357778)2  =−0.1459189
21 2h    21  
2
 2h 
1 = h f  y1 + , t1 +  = h − t1 +  y1 + 
 3 3    3  3  
  0.2  20.1459189  
2

=0.1− 2.1+  0.83357778 −   = −0.11746269


  3  3  
1
Thus, y2 = y (2.2) = y1 + 1 +31 
4
1
=0.83357778+  −0.1459189−30.11746269  = 0.70900104
4
b) Improved tangent method is
0 = h f ( y0 , t0 ) = h ( − t0 y0 2 ) = 0.1( − 2 ) = − 0.2,
0 h   0  
2
 h 
0 = h f  y0 + , t0 +  = h  −  t0 +   y0 +  
 2 2    2  2  
  0.1  0.2  
2

= 0.1  −  2 +  1 −   = − 0.16605
  2  2  

y1 = y ( 2.1) = y0 +0 =1 − 0.16605 = 0.83395

Institute of Lifelong Learning, University of Delhi Pg. 17


Numerical Solutions of Ordinary Differential Equations

1 = h f ( y1 , t1 ) = h ( − t1 y12 ) = 0.1  − 2.1(0.83395) 2  = − 0.14604925,


1 h   1  
2
 h 
1 = h f  y1 + , t1 +  = h  −  t1 +   y1 +  
 2 2    2  2  
  0.14604925  
2

= 0.1  − 2.15  0.83395 −   = − 0.1244866


  2  
y2 = y ( 2.2 ) = y1 +1 = 0.83395 − 0.1244866 = 0.7094634

c) Heun's method :
 0 = h f ( y0 , t0 ) = h ( − t0 y0 2 ) = 0.1( 2 ) = − 0.2
0 = h f ( y0 + 0 , t0 + h ) = h  − ( t0 + h )( y0 + 0 )  = 0.1  − 2.1(1 − 0.2 )  = − 0.1344
2 2
   
1 1
y1 = y ( 2.1) = y0 + (0 +0 ) =1+ ( − 0.2 − 0.1344 ) = 0.8328
2 2
1 = h f ( y1 , t1 ) = h ( − t1 y1 ) = 0.1  − 2.1( 0.8328 )  = − 0.14564673
2 2
 
1 = h f ( y1 + 1 , t1 + h ) = h  − ( t1 + h ) ( y1 + 1 ) 
2
 
= 0.1  − 2.22 ( 0.8328 − 0.14564673)  = − 0.10482388
2
 
1 1
y2 = y ( 2.2 ) = y1 + (1 +1 ) = 0.8328 + ( − 0.14564673 − 0.10482388 ) = 0.70756469
2 2
y
Example 8: Solve the IVP y ' = 3 t + , y (0) =1 and find y ( 0.2 ) with h = 0.1
2
using the following R-K methods of second order

a) Optimal R-K method


b) Improved tangent method
c) Heun's method
Solution: a) Optimal Runge-Kutta, method:
 y0 
 0 = h f ( y0 , t0 ) = h  3 t0 + = 0.1( 0 + 0.5 ) = 0.05
 2 
 2 2h    2 h   y  
0 = h f  y0 + 0 , t0 +  = h 3  t0 +  +  0 + 0  
 3 3    3   2 3 
  2  0.1   0.05  
= 0.1 3  0 +  +  0.5 +  = 0.07166667
  3   3  
Thus,

Institute of Lifelong Learning, University of Delhi Pg. 18


Numerical Solutions of Ordinary Differential Equations

1 1
y 1 = y ( 0.1) = y0 +0 + 30  =1+  0.05 + 3 0.07166667  = 1.06625
4 4
To calculate y2 , we need ,
 y1 
1 = h f ( y1 , t1 ) = h  3 t1 +  = 0.1 0.3 + 0.533125 = 0.0833125
 2
 2 2h    2 h   y  
1 = h f  y1 + 1 , t1 +  = h 3  t1 +  +  1 + 1  
 3 3    3   2 3 

  0.0833125  
= 0.1 0.5 +  0.533125 +   = 0.10608958
  3 
Thus,
1 1
y 2 = y ( 0.2 ) = y1 + 1 + 31  =1.06625 +  0.0833125 + 3 0.10608958 
4 4
= 1.16664531

b) Improved tangent method is


 y0 
0 = h f ( y0 , t0 ) =h3t0 +  =0.1(0+ 0.5) =0.05
 2
 0 h   h   y  
0 = h f  y0 + , t0 +  = h 3t0 +  + 0 + 0 
 2 2   2   2 4 
y1 = y (0.1) = y0 +0 =1+ 0.05=1.05
 y1 
1 = h f ( y1, t1 ) =h3t1 +  =0.10.3+ 0.525=0.0825,
 2
 1 h   h   y1 1 
1 = h f  y1 + , t1 +  = h 3t1 +  + + 
 2 2   2   2 4 
  0.0825 
=0.130.15+ 0.525+  =0.09956
  2 
y2 = y (0.2) = y1 +1 =1.05+ 0.09956 =1.14956

c) Heun's method :
0 = h f ( y0 , t0 ) = h (1 + y0 2 ) = 0.2 (1 + 0 ) = 0.2
0 = h f ( y0 + 0 , t0 + h ) = h 1 + ( y0 + 0 )  = 0.2 1 + ( 0 + 0.2 )  = 0.208
2 2
   
1 1
y1 = y ( 0.2 ) = y0 + (0 +0 ) = 0 + ( 0.2 + 0.208) = 0.204
2 2
1 = h f ( y1 , t1 ) = h (1 + y12 ) = 0.2 1 + ( 0.204 )  = 0.2083232
2
 

Institute of Lifelong Learning, University of Delhi Pg. 19


Numerical Solutions of Ordinary Differential Equations

1 = h f ( y1 + 1 , t1 + h ) = h 1 + ( y1 + 1 )  = 0.2 1 + ( 0.204 + 0.2083232 ) 


2 2
   
= 0.2340020843
1 1
y2 = y ( 0.4 ) = y1 + (1 + 1 ) = 0.204 + ( 0.2083232 + 0.2340020843)
2 2
= 0.4251626422

5.2. Runge-Kutta Method of Fourth order

The Runge-Kutta Method of Fourth order is perhaps the most widely used
method for solving ODEs. One such method results in

h
( ) ( )
yi +1 = yi + i + 2 − 2 i + 2 + 2  i + wi 
6 
(31)

where

i = f ( yi , ti )
 h h
i = f  yi + i , ti + 
 2 2 
 h h h
 i = f  yi + (i −i ) − (i − 2i ) , ti +  (32)
 2 2 2
 h 
wi = f  yi − (i −  i ) + h  i , ti + h  .
 2 

This method is known as Runge-Kutta-GILL method.

Another method with order four Known as Classical Runge-Kutta


method, is widely used method due to its simplicity and moderate order.
We shall also be working out problems mostly by the classical R-K method
unless specified otherwise. This method is given by
h
yi +1 = yi + i + 2i + 2 i + wi  (33)
6
where

Institute of Lifelong Learning, University of Delhi Pg. 20


Numerical Solutions of Ordinary Differential Equations

i = f ( yi , ti )
 h h
i = f  yi + i , ti + 
 2 2 
 h h
 i = f  yi + i , ti +  (34)
 2 2
wi = f ( yi + h  i , ti + h )

In all methods above no information is needed other than the initial

condition. For example, yi is approximated by using y0 ,  0 ,0 , and so on.


The quantities are found from the given equation with no differentiation
required. These reasons, combined with the accuracy of Runge-Kutta
methods, make them extremely popular.

Example 9: Use Classical Runge-Kutta method of fourth-order to solve


the IVP y = 4 − 2 y t , y (0) = 0.2 using h = 0.1. Carry out the solution for two time

steps.

Solution: The first derivative is found from yi =4−2yt


i i . To find yi we must

know y0 ,  0 ,0 ,  0 and w0 . They are

y0 = 0.2,
0 = f ( y0 , t0 ) = 4 − 2 y0 t0 = 4 − 2  0.2  0 = 4,
 h h  h  h
0 = f  y0 + 0 , t0 +  = 4 − 2  y0 + 0  t0 + 
 2 2  2 2  
 0.1  0.1 
= 4 − 2  0.2 +  4   = 3.96,
 2  2 
 h h  h  h
 0 = f  y0 + 0 , t0 +  = 4 − 2  y0 + 0  t0 + 
 2 2  2  2
 0.1   0.1 
= 4 − 2  0.2 +  3.96    = 3.96,
 2  2 
w0 = f ( y0 + h  0 , t0 + h ) = 4 − 2 ( y0 + h  0 )( t0 + h )
= 4 − 2 ( 0.2 + 0.1 3.96 )( 0.1 ) = 3.88

Thus,

Institute of Lifelong Learning, University of Delhi Pg. 21


Numerical Solutions of Ordinary Differential Equations

h
y 1 = y0 + 0 + 20 + 2 0 + w0 
6

0.1
= 0.2 + ( 3.96 + 7.92 + 7.92 + 3.88) = 0.595
6

For next iteration, we start from y1 , and calculate the values of 1 ,1 ,  1 and
w1 . They are

1 = f ( y1 , t1 ) = 4 − 2 y1 t1 = 4 − 2  0.595  0.1 = 3.88,


 h h  h  h
1 = f  y1 + 1 , t1 +  = 4 − 2  y1 + 1  t1 + 
 2 2   2 2  
 0.1  0.1 
= 4 − 2  0.595 +  3.88  0.1 +  = 3.76,
 2  2 
 h h  h  h
 1 = f  y1 + 1 , t1 +  = 4 − 2  y1 + 1  t1 + 
 2 2  2  2
 0.1  0.1 
= 4 − 2  0.595 +  3.76  0.1 +  = 3.77,
 2  2 
w1 = f ( y1 + h  1 , t1 + h ) = 4 − 2 ( y1 + h  1 )( t1 + h )
= 4 − 2 ( 0.595 + 0.1 3.77 )( 0.1 + 01) = 3.61
Thus,
h
y 2 = y1 + 1 + 21 + 2 1 + w1 
6
0.1
= 0.595 + ( 3.88 + 7.52 + 7.54 + 3.61) = 0.971
6
Example 10: Use Classical Runge-Kutta method of fourth-order to solve
the IVP y = y + t , y (0) =1using h = 0.1. Carry out the solution for two time steps.

Solution: The first derivative is found from yi = yi +ti . To find yi we must

know y0 ,  0 ,0 ,  0 and w0 . They are

y0 =1,
0 = f ( y0 , t0 ) = y0 + t0 =1 + 0 =1,
 h h  h   h  0.1   0.1 
0 = f  y0 + 0 , t0 +  =  y0 + 0  +  t0 +  = 1 + 1 +   =1.1,
 2 2  2   2  2   2 

Institute of Lifelong Learning, University of Delhi Pg. 22


Numerical Solutions of Ordinary Differential Equations

 h h  h   h  0.1   0.1 
 0 = f  y0 + 0 , t0 +  =  y0 + 0  +  t0 +  = 1+ 1.1  +   =1.105,
 2 2  2   2  2   2 

Thus,

h 0.1
y 1 = y0 + 0 + 20 + 2 0 + w0  =1+ (1+ 2.2 + 2.210 +1.2105 ) =1.11034
6 6

w0 = f ( y0 + h  0 , t0 + h ) = ( y0 + h  0 ) + ( t0 + h ) = (1 + 0.11.105 ) + ( 0.1 ) =1.2105

For next iteration, we start from y1 , and calculate the values of 1 ,1 ,  1 and
w1 . They are

1 = f ( y1 , t1 ) = y1 + t1 = 1.11034 + 0.1 =1.21034,


 h h   
h h
1 = f  y1 + 1 , t1 +  =  y1 + 1  +  t1 + 
 2 2   2   2
 0.1   0.1 
= 1.11034 + 1.21034  +  0.1 +  =1.320857,
 2   2 
 h h  h   h
 1 = f  y1 + 1 , t1 +  =  y1 + 1  +  t1 + 
 2 2   2   2 
 0.1   0.1 
= 1.11034 + 1.320857  +  0.1 +  =1.32638285,
 2   2 
w1 = f ( y1 + h  1 , t1 + h ) = ( y1 + h  1 ) + ( t1 + h )
= (1.11034 + 0.11.32638285 ) + ( 0.1 + 01) =1.44297829
Thus,
h
y 2 = y1 +1 + 21 + 2 1 + w1 
6
0.1
=1.11034 + (1.21034 + 2.641714 + 2.6527657 +1.44297829 ) =1.2428033
6

Example 11: Use Classical Runge-Kutta method of fourth-order to solve


the IVP y = 2 y + 3 et , y (0) = 0using h = 0.1. Carry out the solution for two time

steps.

Solution: The first derivative is found from yi =2yi +3ei . To find yi we


t

must know y0 ,  0 ,0 ,  0 and w0 . They are

Institute of Lifelong Learning, University of Delhi Pg. 23


Numerical Solutions of Ordinary Differential Equations

y0 = 0,
0 = f ( y0 , t0 ) = 2 y0 + 3 et = 2  0 + 3 e0 = 3,
0

 h
 h h  h   t0 +   0.1 
0 = f  y0 + 0 , t0 +  = 2  y0 + 0  + 3 e 2  = 2  0 +  3  + 3 e0.05
 2 2  2   2 
= 3.453813289,
 h
 h h  h   t0 + 
 0 = f  y0 + 0 , t0 +  = 2  y0 + 0  + 3 e 2 
 2 2  2 
 0.1 
= 20 +  3.453813289  + 3 e0.05 = 3.499194618,
 2 
w0 = f ( y0 + h  0 , t0 + h ) = 2 ( y0 + h  0 ) + 3 e( 0
t + h)

= 2 ( 0 + 0.1 3.499194618 ) + 3 e0.1 = 4.015351678

Thus,

h
y 1 = y0 +0 + 20 + 2 0 + w0 
6
0.1
=0+ ( 3 + 2  3.453813289 + 2  3.499194618 + 4.015351678 ) = 0.3486894582
6

For next iteration, we start from y1 , and calculate the values of 1 ,1 ,  1 and
w1 . They are

1 = f ( y1 , t1 ) = 2 y1 + 3 et = 2  0.3486894582 + 3  e0.1 = 4.012891671,


1

 h
 h h  h   t1 + 
1 = f  y1 + 1 , t1 +  = 2  y1 + 1  + 3e
 2

 2 2  2 
 0.1 
 0.1   0.1+ 
= 2  0.3486894582 +  4.012891671  + 3  e 2 
= 4.584170812,
 2 
 h
 h h  h   t1 + 
 1 = f  y1 + 1 , t1 +  = 2  y1 + 1  + 3 e
 2

 2 2  2 
 0.1 
 0.1   0.1+ 
= 2  0.3486894582 +  4.584170812  + 3  e 2 
= 4.641298726,
 2 
w1 = f ( y1 + h  1 , t1 + h ) = 2 ( y1 + h  1 ) + 3 e( t1 + h )
= 2 ( 0.3486894582 + 0.1 4.641298726 ) + 3  e0.2 = 6.887058455

Thus,

Institute of Lifelong Learning, University of Delhi Pg. 24


Numerical Solutions of Ordinary Differential Equations

h
y 2 = y1 + 1 + 21 + 2 1 + w1 
6
0.1
= 0.3486894582 + ( 4.012891671+ 2  4.584170812 + 2  4.641298726 + 6.887058455)
6
= 0.83787094

Example 12: Use Runge-Kutta Gill method of fourth-order to solve the


IVP y = 2 y + 3 et , y (0) = 0using h = 0.1. Carry out the solution for two time steps.

Solution: The first derivative is found from yi = 2 yi + 3 eti . To find yi we

must know y0 ,  0 ,0 ,  0 and w0 . They are

y0 = 0,
 0 = f ( y0 , t0 ) = 2 y0 + 3 et = 2  0 + 3 e0 = 3,
0

 h
 h h  h   t0 + 
0 = f  y0 + 0 , t0 +  = 2  y0 + 0  + 3 e 2 
 2 2  2 
 0.1 
= 20 +  3  + 3  e0.05 = 3.453813289,
 2 
 h h h
 0 = f  y0 + (0 −0 ) − (0 − 20 ) , t0 + 
 2 2 2
 h
 h h   t0 + 
= 2  y0 + (0 −0 ) − (0 − 20 )  + 3 e 2 
 2 2 
 0.1 
 0.1 0.1   
= 20 +  − 0.4538133 +  3.9076266  +3e
 2 
= 3.480397056,
 2 2 
 h 
w0 = f  y0 − (0 −  0 ) + h  0 , t0 + h 
 2 
 h 
= 2  y0 − (0 −  0 ) + h  0  + 3e
( t0 + h )
= 4.015351678
 2 

Thus,

h
( ) (
y 1 = y0 + 0 + 2 − 2 0 + 2 + 2  0 + w0 
6  )
=0+
0.1
6
( ( ) ( )
3 + 2 − 2  3.453813289 + 2 + 2  3.480397056 + 4.015351678 )
= 0.3486894582

Institute of Lifelong Learning, University of Delhi Pg. 25


Numerical Solutions of Ordinary Differential Equations

For next iteration, we start from y1 , and calculate the values of 1 ,1 ,  1 and
w1 . They are

1 = f ( y1 , t1 ) = 2 y1 + 3 et = 4.012891671,
1

 h
 h h  h   t1 + 
1 = f  y1 + 1 , t1 +  = 2  y1 + 1  + 3 e 2
= 4.584170812,
 2 2   2 
 h h h
 1 = f  y1 + (1 −1 ) − (1 − 21 ) , t1 + 
 2 2 2
 h
 h h   t1 + 
= 2  y1 + (1 −1 ) − (1 − 21 )  + 3 e 2  = 4.617635569,
 2 2 

 h 
w1 = f  y1 − (1 −  1 ) + h  1 , t1 + h 
 2 
 h 
= 2  y1 − (1 −  1 ) + h  1  + 3 e( t1 + h) = 5.289846936
 2 
Thus,
h
( ) ( )
y 2 = y1 + 1 + 2 − 2 1 + 2 + 2  1 + w1  = 0.8112507529
6 

Summary:

We now end this chapter by giving a summary of it. In this chapter we


have covered the following

(1) The steps involved in solving the IVP y ' = f ( y, t ) , y (t 0 ) = y0 , t  t 0 , b 

by Euler's method are as follows :


Step 1: Evaluate f ( y0 , t0 )

Step 2: Find y1 = y0 + h f ( y0 , t0 )

Step 3: If t0  b, change t0 tot0 + h and y0 to y1 and repeat steps 1

and 2

Step 4: If t 0 = b , write the value of y1.


(2) Runge-Kutta methods being single step methods are self- starting
methods.

Institute of Lifelong Learning, University of Delhi Pg. 26


Numerical Solutions of Ordinary Differential Equations

(3) Unlike Taylor series methods, R-K methods do not need


calculation of higher order derivatives f(y, t) but need only the
evaluation of f(y, t) at the off-step points.

Exercise:
1. Use Euler’s method to Solve the IVP
dy
= 4 − 2 y t , y (0) = 0.2. Find y (0.4) with h = 0.1 .
dt
1
2. Solve the IVP y ' = , y ( 4 ) = 4, by Euler's method using h = 0.1. Carry
x −4 y
2

out the solution for five time steps. Find the exact error.

3. Use Euler method to find the solution of y ' = t + y , given y ( 0 ) = 1. Find the

solution on [0, 0.8] with h = 0.2..


4. Solve the IVP y ' =1+ y 2 , y (0) =1 and find Find y ( 0.6 ) taking h = 0.2 and h = 0.1

using the Euler’s methods.


5. Solve the IVP y ' = − t y 2 , y (2) =1 and find y ( 2.1) and y ( 2.2 ) taking h = 0.1 using

the following R-K methods of second order

a) Optimal R-K method


b) Improved tangent method
1
c) Heun's method 6. Solve the IVP y ' = 3t + y , y (0) =1 and find
2
y ( 2.1) and y ( 2.2 ) taking h = 0.1 using the following R-K methods of second

order

a) Optimal R-K method


b) Improved tangent method
c) Heun's method

Compare the results with the exact solution y ( t ) =13 e t/2 − 6 t −12, and find the

errors.
Institute of Lifelong Learning, University of Delhi Pg. 27
Numerical Solutions of Ordinary Differential Equations

7. Use Optimal Runge-Kutta method of second-order to solve the IVP


10 y ' = y 2 + t 2 , y (0.2) =1, using h = 0.1.

8. Use Classical Runge-Kutta method of fourth-order to solve the IVP


y = y + t , y (0) =1, using h = 0.1. Carry out the solution for five time steps. Also

find the error at t = 0.5, if the exact solution is y ( t ) = 2 et − t −1.

9. Solve the IVP y ' = 2 y + 3 et , y (0) = 0 and find y ( 2.1) and y ( 2.2 ) taking h = 0.1

using the following R-K methods of second order

a) Classical R-K method of fourth-order


b) R-K Gill method of fourth-order

10. Use Runge-Kutta Gill method of fourth-order to solve the IVP


dy
=1 − 2 y t , y (0.2) = 0.1948. Find y (0.2) with h = 0.2 .
dt
Glossary:

B Boundary conditions: n conditions which are prescribed at more


than one point.
Boundary value problem (BVP): Differential equation together
with the boundary.
C Classical Runge-Kutta Method of fourth:

h
yi +1 = yi + i +2i +2i + wi 
6
where
i = f ( yi ,ti )
 h h
i = f  yi + i ,ti + 
 2 2 
 h h
i = f  yi + i ,ti + 
 2 2
wi = f ( yi + hi ,ti +h)

E Euler’s Method:
Institute of Lifelong Learning, University of Delhi Pg. 28
Numerical Solutions of Ordinary Differential Equations

yi+1 =hyi ,

where h = t = ti +1 − ti , is the step size.

H Henu’s Method: The Runge-Kutta method of second order also

known as the Euler-Cauchy method is

1
yi +1 = yi + (  i + i )
2
where
i = h f ( yi , ti )
i = h f ( yi + i , ti + h )

I Improved Tangent Method: The Runge-Kutta method of second

order also known as the modified Euler's method.

yi +1 = yi +i
where
i = h f ( yi , ti )
  h
i = h f  yi + i , ti + 
 2 2

O Optimal Runge-Kutta Method: A second order Runge-Kutta method

given by

1
yi +1 = yi + i + 3i 
4
where
i = h f ( yi , ti )
 2 2h 
i = h f  yi + i , ti + 
 3 3 

R Runge-Kutta Gill Method: A fourth order Runge-Kutta method

given by
h
( ) ( )
yi +1 = yi + i + 2 − 2 i + 2 + 2  i + wi 
6 

Where

Institute of Lifelong Learning, University of Delhi Pg. 29


Numerical Solutions of Ordinary Differential Equations

i = f ( yi , ti )
 h h
i = f  yi + i , ti + 
 2 2 
 h h h
 i = f  yi + (i −i ) − (i − 2i ) , ti + 
 2 2 2
 h 
wi = f  yi − (i −  i ) + h  i , ti + h  .
 2 

References:

1. C. F. Gerald, P. O. Wheatley: Applied Numerical Analysis,


Pearson Education, India, 7th edition, (2008)
2. Uri M. Ascher, Chen Greif: A first course in Numerical
Methods, PHI Learning Private Limited, (2013)
3. John H. Mathews, Kurtis D. Fink: Numerical Methods using
Matlab, 4th Edition, PHI Learning Private Limited, (2013)
4. K. E. Atkinson, Introduction to Numerical Analysis, John Wiley
and Sons, 2nd edition, (1989).
5. Hadamard J., Lectures on Cauchy’s Problem in Linear Partial
Differential Equations, Dover Publications, New York (1952).

Institute of Lifelong Learning, University of Delhi Pg. 30

You might also like