Math 23 Module 6
Math 23 Module 6
Module 6: Ordinary
Differential Equations
Prepared by:
Overview
In this module, we will discuss the one-step methods for solving initial-value problems. One-step
methods permit the calculation of 𝑦𝑖+1 , given the differential equation and 𝑦𝑖 . The one-step methods
belong to what are called Runge-Kutta techniques. Although the module might have been organized
around this theoretical notion, we have opted for a more graphical, intuitive approach to introduce the
methods. Thus, we begin the module with Euler’s method, which has a very straightforward graphical
interpretation. Then, we use visually oriented arguments to develop two improved versions of Euler’s
method—the Heun and the midpoint techniques. After this introduction, we formally develop the
concept of Runge-Kutta (or RK) approaches and demonstrate how the foregoing techniques are
actually first- and second-order RK methods.
Learning Outcomes
At the end of this module, you should be able to:
1. Apply one-step methods for solving initial-value ordinary differential equations.
6.1 INTRODUCTION
Mathematical Background
A solution of an ordinary differential equation is a specific function of the independent variable and
parameters that satisfies the original differential equation. To illustrate this concept, let us start with a
given function
𝑦 = −0.5𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥 + 1 (6.1)
which is a fourth-order polynomial (Fig. 6.1a). Now, if we differentiate Eq. (6.1), we obtain an ODE:
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 (6.2)
𝑑𝑥
This equation also describes the behavior of the polynomial, but in a manner different from Eq. (6.1).
Rather than explicitly representing the values of 𝑦 for each value of 𝑥, Eq. (6.2) gives the rate of
change of 𝑦 with respect to 𝑥 (that is, the slope) at every value of 𝑥. Figure 6.1 shows both the function
and the derivative plotted versus 𝑥. Notice how the zero values of the derivatives correspond to the
point at which the original function is flat—that is, has a zero slope. Also, the maximum absolute
values of the derivatives are at the ends of the interval where the slopes of the function are greatest.
Although, as just demonstrated, we can determine a differential equation given the original
function, the object here is to determine the original function given the differential equation. The
original function then represents the solution. For the present case, we can determine this solution
analytically by integrating Eq. (6.2):
𝑦 = ∫(−2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5) 𝑑𝑥
Applying the integration rule
𝑛
𝑢𝑛+1
∫ 𝑢 𝑑𝑢 = +𝐶 𝑛 ≠ −1
𝑛+1
to each term of the equation gives the solution
𝑦 = −0.5𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥 + 𝐶 (6.3)
which is identical to the original function with one notable exception. In the course of differentiating
and then integrating, we lost the constant value of 1 in the original equation and gained the value 𝐶.
This 𝐶 is called a constant of integration. The fact that such an arbitrary constant appears indicates
that the solution is not unique. In fact, it is but one of an infinite number of possible functions
(corresponding to an infinite number of possible values of 𝐶) that satisfy the differential equation. For
example, Fig. 6.2 shows six possible functions that satisfy Eq. (6.3).
Figure 6.2 Six Possible Solutions for the Integral of −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5
Runge-Kutta Methods
This module is devoted to solving ordinary differential equations of the form
𝑑𝑦
= 𝑓(𝑥, 𝑦)
𝑑𝑥
having the general form
New value = old value + slope × step size
or, in mathematical terms,
𝑦𝑖+1 = 𝑦𝑖 + 𝜙ℎ (6.6)
According to this equation, the slope estimate of 𝜙 is used to extrapolate from an old value 𝑦𝑖 to a
new value 𝑦𝑖+1 over a distance ℎ (Fig. 6.3). This formula can be applied step by step to compute out
into the future and, hence, trace out the trajectory of the solution.
All one-step methods can be expressed in this general form, with the only difference being the
manner in which the slope is estimated. The simplest approach is to use the differential equation to
estimate the slope in the form of the first derivative at 𝑥𝑖 . In other words, the slope at the beginning
Example 6.1
Use Euler’s method to integrate Eq. (6.2):
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5
𝑑𝑥
from 𝑥 = 0 to 𝑥 = 4 with a step size of 0.5. The initial condition at 𝑥 = 0 is 𝑦 = 1. Recall that the exact
solution is given by Eq. (6.5):
𝑦 = −0.5𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥 + 1
Solution
1st Step:
Equation (6.7) can be used to implement Euler’s method:
𝑦(0.5) = 𝑦(0) + 𝑓(0,1)0.5
where 𝑦(0) = 1 and the slope estimate at 𝑥 = 0 is
𝑓(0,1) = −2(0)3 + 12(0)2 − 20(0) + 8.5 = 8.5
Therefore,
𝑦(0.5) = 1 + (8.5)0.5 = 5.25
Math 23 – Advanced Mathematics Engr. Michael Ernie F. Rodriguez | Page 4
The true solution at 𝑥 = 0.5 is
𝑦 = −0.5(0.5)4 + 4(0.5)3 − 10(0.5)2 + 8.5(0.5) + 1 = 3.21875
2nd Step:
Equation (6.7) can be used to implement Euler’s method:
𝑦(1) = 𝑦(0.5) + 𝑓(0.5,5.25)0.5
The slope estimate at 𝑥 = 0.5 is
𝑓(0.5,5.25) = −2(0.5)3 + 12(0.5)2 − 20(0.5) + 8.5 = 1.25
Therefore,
𝑦(1) = 5.25 + (1.25)0.5 = 5.875
The true solution at 𝑥 = 0.5 is
𝑦 = −0.5(1)4 + 4(1)3 − 10(1)2 + 8.5(1) + 1 = 3
The computation is repeated, and the results are compiled in Table 6.1 and Fig. 6.5.
Table 6.1 Comparison of True Value and Approximate Value Using Euler’s Method
𝑥 𝑦true 𝑦Euler
0.0 1.00000 1.00000
0.5 3.21875 5.25000
1.0 3.00000 5.87500
1.5 2.21875 5.12500
2.0 2.00000 4.50000
2.5 2.71875 4.75000
3.0 4.00000 5.87500
3.5 4.71875 7.12500
4.0 3.00000 7.00000
Figure 6.5 Comparison of the True Solution with a Numerical Solution Using Euler’s Method
Heun’s Method
One method to improve the estimate of the slope involves the determination of two derivatives for the
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. This approach, called Heun’s
method, is depicted graphically in Fig. 6.6.
Figure 6.6 Graphical Depiction of Heun’s Method. (a) Predictor and (b) Corrector
Example 6.2
Use Heun’s method to integrate Eq. (6.2):
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5
𝑑𝑥
from 𝑥 = 0 to 𝑥 = 4 with a step size of 0.5. The initial condition at 𝑥 = 0 is 𝑦 = 1.
Solution
1st Step:
According to Euler’s method:
𝑦(0.5) = 𝑦(0) + 𝑓(0,1)0.5
where 𝑦(0) = 1 and the slope estimate at 𝑥 = 0 is
𝑓(0,1) = −2(0)3 + 12(0)2 − 20(0) + 8.5 = 8.5
Therefore,
𝑦(0.5) = 1 + (8.5)0.5 = 5.25
The slope estimate at 𝑥 = 0.5 is
𝑓(0.5,5.25) = −2(0.5)3 + 12(0.5)2 − 20(0.5) + 8.5 = 1.25
Therefore,
8.5 + 1.25
𝑦 ′ (0.5) = = 4.875
2
𝑦(0.5) = 1 + (4.875)0.5 = 3.4375
nd
2 Step:
According to Euler’s method:
𝑦(1) = 𝑦(0.5) + 𝑓(0.5,5.25)0.5
The slope estimate at 𝑥 = 0.5 is
𝑓(0.5,5.25) = −2(0.5)3 + 12(0.5)2 − 20(0.5) + 8.5 = 1.25
Therefore,
𝑦(1) = 5.25 + (1.25)0.5 = 5.875
The slope estimate at 𝑥 = 1 is
𝑓(1,5.875) = −2(1)3 + 12(1)2 − 20(1) + 8.5 = −1.5
Therefore,
1.25 + (−1.5)
𝑦 ′ (1) = = −0.125
2
𝑦(1) = 3.4375 + (−0.125)0.5 = 3.375
The computation is repeated, and the results are compiled in Table 6.2 and Fig. 6.6.
The midpoint method is superior to Euler’s method because it utilizes a slope estimate at the
midpoint of the prediction interval.
Solution
Using Midpoint Method,
1st Step:
Compute for 𝑘1 and 𝑘2 ,
𝑘1 = −2(0)3 + 12(0)2 − 20(0) + 8.5 = 8.5
𝑘2 = −2(0.25)3 + 12(0.25)2 − 20(0.25) + 8.5 = 4.21875
Therefore,
𝑦(0.5) = 1 + 4.21875(0.5) = 3.109375
nd
2 Step:
Compute for 𝑘1 and 𝑘2 ,
𝑘1 = −2(0.5)3 + 12(0.5)2 − 20(0.5) + 8.5 = 1.25
𝑘2 = −2(0.75)3 + 12(0.75)2 − 20(0.75) + 8.5 = −0.59375
Therefore,
𝑦(1) = 3.109375 + (−0.59375)(0.5) = 2.8125
The computation is repeated, and the results are summarized in Table 6.3 and Fig. 6.9.
EXERCISE SET
1. Solve the following initial value problem over the interval from 𝑡 = 0 to 2 where 𝑦(0) = 1. Display
all your results on the same graph.
𝑑𝑦
= 𝑦𝑡 2 − 1.1𝑦
𝑑𝑡
(a) Analytically.
(b) Euler’s method with ℎ = 0.5 and 0.25.
(c) Midpoint method with ℎ = 0.5.
(d) Ralston’s method with ℎ = 0.5.
2. Solve the following problem over the interval 𝑥 = 0 to 1 using a step size of 0.25 where 𝑦(0) = 1.
Display all your results on the same graph.
𝑑𝑦
= (1 + 4𝑥)√𝑦
𝑑𝑥
SUPPLEMENTARY READING
Read Chapter 28: Case Studies for Ordinary Differential Equations on the book Numerical
Methods for Engineers (7th ed.) by Chapra and Canale. The purpose of this supplementary reading
is to solve some ordinary differential equations using the numerical methods presented in this module.
The equations originate from practical engineering applications. Many of the applications
result in nonlinear differential equations which cannot be solved using analytic techniques. Therefore,
numerical methods are usually required. Thus, the techniques for the numerical solution of ordinary
differential equations are fundamental capabilities that characterize good engineering practice.
REFERENCES
1. Chapra, S. C., Canale, R. P. (2015). Numerical Methods for Engineers (7th ed.). The McGraw-Hill
Companies, Inc.
2. Chapra, S. C. (2018). Applied Numerical Methods with MATLAB® for Engineers and Scientists
(4th ed.). The McGraw-Hill Companies, Inc.