You are on page 1of 20

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Numerical Solution of Ordinary


Differential Equations

Dheeraj K Khatod, EED


Basics about Differential Equations
• An equation relating one or more functions/variables and their derivatives.
• The variables generally represent physical quantities and the derivatives
represent their rates of change, and the differential equation defines a
relationship between the two. Such relations are common, therefore
differential equations play a prominent role in many disciplines including
engineering, physics, economics, and biology.
• Differential equations can be of two types:
– Ordinary differential equations:
• A differential equation containing only one independent variable with
respect to which derivatives are computed.
• For example,
𝑑𝑑𝑑𝑑
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 Here, 𝑥𝑥 is independent variable.
𝑑𝑑𝑑𝑑
– Partial differential equations:
• A differential equation containing more than one independent variables with
respect to which derivatives are computed.
• For example,
𝜕𝜕𝑧𝑧 𝜕𝜕𝜕𝜕
+ = 𝑓𝑓 𝑥𝑥, 𝑦𝑦, 𝑧𝑧 Here, 𝑥𝑥 and 𝑦𝑦 are independent variables.
𝜕𝜕𝜕𝜕 𝜕𝜕𝜕𝜕

2
Ordinary Differential Equations
• The order of an ordinary differential equation is the order
of the highest derivative term in it.
• The degree of an ordinary differential is the exponent of
the highest order derivative provided that neither
dependent variable nor its derivatives should appear
under radical sign.
• For example, the differential equation
𝑑𝑑2𝑦𝑦 𝑑𝑑𝑑𝑑
+ + 𝑦𝑦 = 0 has both order and degree as 2.
𝑑𝑑𝑑𝑑2 𝑑𝑑𝑑𝑑
as above equation can be written as
2
𝑑𝑑 2 𝑦𝑦 𝑑𝑑 2 𝑦𝑦 𝑑𝑑𝑑𝑑
+ 2𝑦𝑦 2 − + 𝑦𝑦 2 = 0
𝑑𝑑𝑥𝑥 2 𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑

3
Ordinary Differential Equations
(Contd…)
• Ordinary differential equations can be of two types:
• Linear
– Dependent variable and its derivatives are of degree 1 and
there is no product of dependent variable and its
derivatives.
– For example,
2
𝑑𝑑 𝑦𝑦 𝑑𝑑𝑑𝑑 2
𝑑𝑑 𝑦𝑦 𝑑𝑑𝑑𝑑
𝑥𝑥 2 2 + + 𝑦𝑦 = 𝑒𝑒 𝑥𝑥
and 𝑥𝑥 2 2 + 𝑒𝑒 𝑥𝑥 + 4𝑦𝑦 = cos 𝑥𝑥
𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑 𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑

• Non-linear
– Ordinary differential equations not fulfilling linear property
– For example,
2 2
𝑑𝑑 𝑦𝑦 𝑑𝑑𝑑𝑑 𝑑𝑑 2 𝑦𝑦 𝑑𝑑𝑑𝑑
𝑦𝑦 2 2 + 𝑥𝑥 3
+ 𝑦𝑦 = 𝑒𝑒 𝑥𝑥
and + 𝑥𝑥 3 + 4 ln𝑦𝑦 = 0
𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑 𝑑𝑑𝑥𝑥 2 𝑑𝑑𝑑𝑑

4
System of First Order Ordinary
Differential Equations
• Consider an nth order ordinary differential equation:
𝑑𝑑 𝑛𝑛 𝑦𝑦 𝑑𝑑𝑑𝑑 𝑑𝑑 2 𝑦𝑦 𝑑𝑑 𝑛𝑛−1 𝑦𝑦
𝑛𝑛
= 𝑓𝑓(𝑥𝑥, 𝑦𝑦, , 2 , … , 𝑛𝑛−1 )
𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑 𝑑𝑑𝑥𝑥 𝑑𝑑𝑥𝑥
• Above equation of nth order can be reduced to a set of
first order ordinary differential equations by
introducing new/dummy variables as:
𝑑𝑑𝑑𝑑 𝑑𝑑 2 𝑦𝑦 𝑑𝑑𝑧𝑧1 𝑑𝑑 𝑛𝑛−1 𝑦𝑦 𝑑𝑑𝑧𝑧𝑛𝑛−2
= 𝑧𝑧1 , = = 𝑧𝑧2 , … , 𝑛𝑛−1 = = 𝑧𝑧𝑛𝑛−1
𝑑𝑑𝑑𝑑 𝑑𝑑𝑥𝑥 2 𝑑𝑑𝑑𝑑 𝑑𝑑𝑥𝑥 𝑑𝑑𝑑𝑑
• A system of n simultaneous equations of first order is
given as:
𝑑𝑑𝑑𝑑 𝑑𝑑𝑧𝑧1 𝑑𝑑𝑧𝑧𝑛𝑛−2 𝑑𝑑𝑧𝑧𝑛𝑛−1
= 𝑧𝑧1 , = 𝑧𝑧2 , … , = 𝑧𝑧𝑛𝑛−1 , = 𝑓𝑓(𝑥𝑥, 𝑦𝑦, 𝑧𝑧1 , 𝑧𝑧2 , … , 𝑧𝑧𝑛𝑛−1 )
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑

5
Solution of Ordinary Differential
Equations
• There are standard methods to find analytical solutions to
linear ordinary differential equations.
• But no such technique are available for the non-linear
equations except for some special cases.
• The differential equations arising in the practical
situations are generally quite complex and nonlinear in
nature. Such type of differential equations are solved by
numerical methods which is the only resource.
• The numerical methods are easy to apply on all kinds of
differential equations and provide solutions to a desired
accuracy. These methods are based on approximation of
Taylor series expansion.

6
Euler’s Method
• One of the simplest numerical methods for solving
linear ordinary differential equation.
• Consider following linear ordinary differential
equation (initial value problem)
𝑑𝑑𝑑𝑑
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 given 𝑦𝑦 = 𝑦𝑦0 at 𝑥𝑥 = 𝑥𝑥0
𝑑𝑑𝑑𝑑
• The value of 𝑦𝑦 at corresponding 𝑥𝑥 can be predicted by
following recursive relation of Euler’s method:
𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 ℎ, 𝑖𝑖 = 0, 1, 2, …
where, h is the step size i.e. distance between two consecutive
points of 𝑥𝑥, i.e.
ℎ = 𝑥𝑥1 − 𝑥𝑥0 = 𝑥𝑥2 − 𝑥𝑥1 = ⋯ = 𝑥𝑥𝑖𝑖+1 −𝑥𝑥𝑖𝑖

7
Graphical Depiction of Euler’s Method

8
Predictor–Corrector Approach

• A fundamental source of error in Euler’s method is


that the derivative at the beginning of an interval is
assumed to be same across that interval.
• One method to improve the estimate of the slope
involves the determination of two derivatives for an
interval, one at the initial point and another at the end
point. The two derivatives are then averaged to obtain
an improved estimate of the slope for the entire
interval.

9
Heun’s Method

• A predictor-corrector approach, sometimes referred to as


modified Euler’s method
• Consider following linear ordinary differential equation
(initial value problem)
𝑑𝑑𝑑𝑑
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 given 𝑦𝑦 = 𝑦𝑦0 at 𝑥𝑥 = 𝑥𝑥0
𝑑𝑑𝑑𝑑
• The value of 𝑦𝑦 at corresponding 𝑥𝑥 can be predicted by
following recursive relation of Heun’s method:
0
Predictor: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 ℎ
0
𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 + 𝑓𝑓 𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1
Corrector: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + ℎ,
2
𝑖𝑖 = 0, 1, 2, …
where, h is the step size i.e. distance between two consecutive
points of 𝑥𝑥, i.e. ℎ = 𝑥𝑥1 − 𝑥𝑥0 = 𝑥𝑥2 − 𝑥𝑥1 = ⋯ = 𝑥𝑥𝑖𝑖+1 −𝑥𝑥𝑖𝑖

10
Graphical Depiction of Heun’s Method

Predictor Corrector

11
Multi-Step Predictor–Corrector
Approach
• The one-step methods described previously utilize
information at a single point 𝑥𝑥𝑖𝑖 to predict a value of
the dependent variable 𝑦𝑦𝑖𝑖+1 at a future point 𝑥𝑥𝑖𝑖+1 .
• Alternative approaches, called multistep methods, use
valuable information from previous points.
• The principle behind a multi-step method is to utilize
the past values of y to construct a polynomial that
approximates the derivative function, and extrapolate
this into the next interval.

12
Multi-Step Predictor–Corrector
Approach (contd…)
• Consider following linear ordinary differential equation
𝑑𝑑𝑑𝑑
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 ,
𝑑𝑑𝑑𝑑
given two known points 𝑥𝑥0 , 𝑦𝑦0 and (𝑥𝑥−1 , 𝑦𝑦−1 )
• The value of 𝑦𝑦 at corresponding 𝑥𝑥 can be predicted by
following recursive relation of Multi-Step Predictor-
Corrector Approach:
0 𝑚𝑚
Predictor: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖−1 + 2𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖𝑚𝑚 ℎ
𝑚𝑚 𝑗𝑗−1
𝑗𝑗 𝑓𝑓 𝑥𝑥 , 𝑦𝑦
𝑖𝑖 𝑖𝑖 + 𝑓𝑓 𝑥𝑥 , 𝑦𝑦
𝑖𝑖+1 𝑖𝑖+1
Corrector: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖𝑚𝑚 + ℎ,
2
𝑗𝑗 = 1, 2, … , 𝑚𝑚 (number of iterations) and 𝑖𝑖 = 0, 1, 2, …
𝑚𝑚
where, 𝑦𝑦𝑖𝑖−1 and 𝑦𝑦𝑖𝑖𝑚𝑚 are the final results of the corrector iterations at the
previous steps. h is the step size i.e. distance between two consecutive
points of 𝑥𝑥, i.e. ℎ = 𝑥𝑥1 − 𝑥𝑥0 = 𝑥𝑥2 − 𝑥𝑥1 = ⋯ = 𝑥𝑥𝑖𝑖+1 −𝑥𝑥𝑖𝑖

13
Runge-Kutta’s Methods
• Although Euler’s method is easy to implement, this
method is not so efficient in the sense that to get a better
approximation, one need a very small step size.
• One way to get a better accuracy is to include the higher
order terms in the Taylor expansion in the formula. But
the higher order terms involve higher derivatives of y.
• The Runge-Kutta (R-K) methods attempt to obtain greater
accuracy and at the same time avoid the need for higher
derivatives, by estimating the function 𝑓𝑓 𝑥𝑥, 𝑦𝑦 or slope at
selected points on each subintervals. Hence, R-K methods
have several forms depending on the estimate of slope at
different number of points.

14
Runge-Kutta’s Methods (contd…)
• Consider following linear ordinary differential equation (initial value
problem)
𝑑𝑑𝑑𝑑
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 given 𝑦𝑦 = 𝑦𝑦0 at 𝑥𝑥 = 𝑥𝑥0
𝑑𝑑𝑑𝑑
• In general, a R-K method of order n can be written as follows
𝑘𝑘1 = 𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖
𝑘𝑘2 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + 𝑝𝑝1 ℎ, 𝑦𝑦𝑖𝑖 + 𝑞𝑞11 𝑘𝑘1 ℎ
𝑘𝑘3 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + 𝑝𝑝2 ℎ, 𝑦𝑦𝑖𝑖 + 𝑞𝑞21 𝑘𝑘1 ℎ + 𝑞𝑞22 𝑘𝑘2 ℎ

𝑘𝑘𝑛𝑛 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + 𝑝𝑝𝑛𝑛−1 ℎ, 𝑦𝑦𝑖𝑖 + 𝑞𝑞𝑛𝑛−1,1 𝑘𝑘1 ℎ + 𝑞𝑞𝑛𝑛−1,2 𝑘𝑘2 ℎ + ⋯ + 𝑞𝑞𝑛𝑛−1,𝑛𝑛−1 𝑘𝑘𝑛𝑛−1 ℎ

𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑎𝑎1 𝑘𝑘1 + 𝑎𝑎2 𝑘𝑘2 + ⋯ + 𝑎𝑎𝑛𝑛−1 𝑘𝑘𝑛𝑛−1 + 𝑎𝑎𝑛𝑛 𝑘𝑘𝑛𝑛 ℎ
where, the p’s, q’s and a’s are constants. h is the step size i.e. distance
between two consecutive points of 𝑥𝑥, i.e.
ℎ = 𝑥𝑥1 − 𝑥𝑥0 = 𝑥𝑥2 − 𝑥𝑥1 = ⋯ = 𝑥𝑥𝑖𝑖+1 −𝑥𝑥𝑖𝑖
• Out of different forms of R-K methods, second-order and fourth-
order are widely used.

15
Second-Order R-K Method
• In second-order R-K method, two estimates of slope at
different points in the interval are made (i.e., two
values of k’s are computed) as:
𝑘𝑘1 = 𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖
𝑘𝑘2 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + ℎ, 𝑦𝑦𝑖𝑖 + 𝑘𝑘1 ℎ
1
𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑘𝑘1 + 𝑘𝑘2 ℎ
2
• Hence, second-order Runge-Kutta method is actually
Heun’s technique.

16
Fourth-Order R-K Method
• In fourth-order R-K method, four estimates of slope at
different points in the interval are made (i.e., four
values of k’s are computed) as:
𝑘𝑘1 = 𝑓𝑓 𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖
1 1
𝑘𝑘2 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + ℎ, 𝑦𝑦𝑖𝑖 + 𝑘𝑘1 ℎ
2 2
1 1
𝑘𝑘3 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + ℎ, 𝑦𝑦𝑖𝑖 + 𝑘𝑘2 ℎ
2 2
𝑘𝑘4 = 𝑓𝑓 𝑥𝑥𝑖𝑖 + ℎ, 𝑦𝑦𝑖𝑖 + 𝑘𝑘3 ℎ
1
𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑘𝑘1 + 2𝑘𝑘2 + 2𝑘𝑘3 + 𝑘𝑘4 ℎ
6
17
Graphical Depiction of the Slope Estimates in
Fourth-Order R-K Method

18
Suggested Readings
• S C Chapra & R P Canale, “Numerical Methods for
Engineers”, McGraw-Hill.
(https://drive.google.com/file/d/1C9w_yvfzXLlwNXi
QrGA1A_roN1H862wk/view?usp=sharing)
• Jaan Kiusalaas, “Numerical Methods in Engineering
With MATLAB”, Cambridge University Press.
(https://drive.google.com/file/d/1UtCk36Z18j5Kmsfj
Aeb_jDMCsqwqm3mf/view?usp=sharing)
• R L Burden, J D Faires & A M Burden, “Numerical
Analysis”, Cengage Learning.
(https://drive.google.com/file/d/1XfwSj1HhhZXWdO
TT_0ZA_ng_SNraIuJb/view?usp=sharing)

19
Thanks

20

You might also like