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

Chapter 6

Ordinary Differential Equations

Differential equations are equations that involve derivatives of an un-


known function. For example, the following is a very simple differential
equation involving the function y:

dy
= y. (6.1)
dt
Equation (6.1) is known as an ordinary differential equation, or
ODE, because it involves only one independent variable, t. Partial differen-
tial equations (PDEs) also exist, but are outside the scope of this subject.
Differential equations are used extensively in mathematical modelling.
Any process involving quantities that change with respect to others can be
modelled using differential equations. Differential equations that describe
how a quantity changes in time are particularly common. For this reason, t,
rather than x, is generally used as the independent variable in an ODE.
Equation (6.1) asserts that the rate of change of y with respect to t is
equal to y itself. What functions y satisfy this property? In this case, the
answer is easy: y = et has a derivative equal to itself. In fact, y = Cet is the
general solution to this ODE, where C is an arbitrary constant.
For certain classes of ODEs, it is possible to obtain an explicit form of
the solution, as we did for equation (6.1). In many cases however, this is
not possible, and we must resort to numerical methods to find approximate
solutions. In this chapter we examine some numerical methods for solving
ODEs.

1
6.1 Problem statement
While solutions with arbitrary constants, such as y = Cet , are fine in purely
theoretical scenarios, in real life we require a definitive solution with no un-
known or arbitrary values. After all, how can we predict the future behaviour
of a process if we don’t know which out of a whole family of solutions is the
correct one for that process?
In the case of (6.1), if we are given the additional piece of information
that y = 1 when t = 0, then we can deduce the value of C that belongs to
our problem. In the case just mentioned, it would be C = 1.
The condition that y = 1 when t = 0 is known as an initial condition.
It is this additional piece of information that is required to pin down precisely
which solution, out of the whole family of possible solutions, relates to the
particular process under consideration. An ODE combined with an initial
condition is called an initial value problem (IVP).
We are now in the position to describe, in general terms, the initial value
problem considered in this chapter: it is to solve the ODE

dy
= f (t, y), a≤t≤b (6.2)
dt
with the initial condition
y(a) = α . (6.3)

Note that the right hand side of the ODE is allowed to depend on both the
independent variable t and the dependent variable y.

Example 6.1 Write down f (t, y) for the following ODEs:


 3
dy t dy t
(a) ′
= ; (b) yy − 1 = 0; (c) − y = t + 1; (d) = y 2.
dt y dt y′

Example 6.2 Verify that y = t2 + 1/t is the solution to the IVP

dy y
= 3t − , y(1) = 2.
dt t

2
6.2 Euler’s method
(Bradie, Section 7.2)

Similar to the approach we took in the previous chapter on quadrature,


consider dividing the interval [a, b] up into n subintervals, each of width h.
Then h = (b − a)/n and ti = a + ih, i = 0, 1, . . . n, so that t0 = a and tn = b.
Our method will be to compute approximations to each value yi = y(ti)
which we will denote by wi . i.e.

wi ≈ y i , i = 0, 1, . . . n .

Euler’s method, also known as the first order Taylor method, uses
a Taylor polynomial approximation of y over each subinterval. Assuming the
solution y is twice differentiable, we have:

y(ti + h) = y(ti ) + hy ′ (ti ) + O(h2 ) .

Note that for brevity we do not show the exact form of the remainder term,
but only its order in terms of h. Using (6.2), and noting that ti + h = ti+1 ,
we obtain:
yi+1 = yi + hf (ti , yi) + O(h2 ) . (6.4)

Dropping the remainder term, and replacing the exact solution yi with the
approximate solution wi , we obtain Euler’s method:

w0 = α,
wi+1 = wi + hf (ti , wi ), i = 0, 1, . . . n − 1 .

Example 6.3 Use Euler’s method with h = 0.25 to solve the initial value
problem

dy y
= 3t − , 1≤t≤2
dt t
y(1) = 2 .

Local and global error


The local error of a numerical ODE-solving method is defined to be the

3
error that the method would incur in one step, assuming the solution was
correct at the previous step. From equation (6.4) it is clear that the local
error for Euler’s method is O(h2 ).
The global error is defined to be the error in the solution at step i, and
is given by |yi − wi |. It can be thought of as the accumulation of all the local
errors from steps 1, 2, . . . i. When we speak of the “order of the method”, it
is the global error of the method to which we refer. It can be shown that the
global error of Euler’s method is O(h), which explains why it is also known
as the first order Taylor method.
In fact, it can be shown that for all Taylor polynomial based methods, if
the local error is O(hn ), then the global error is O(hn−1 ). This is analogous to
the results obtained in the previous chapter on quadrature, where an O(hn )
quadrature method over each subinterval [ti , ti+1 ] resulted in an O(hn−1 )
method over [a, b].

6.3 Second order Taylor method


(Bradie, Section 7.3)

To improve on the accuracy of Euler’s method, we can simply use more


terms in the Taylor polynomial approximation of y over each subinterval.
For example, assuming the solution y is three times differentiable, we have:

h2 ′′
y(ti + h) = y(ti ) + hy ′(ti ) + y (ti ) + O(h3 ) .
2
Again, using (6.2), we obtain:

h2 ′
yi+1 = yi + hf (ti , yi ) + f (ti , yi) + O(h3 ) . (6.5)
2
Dropping the remainder term, and replacing the exact solution yi with the
approximate solution wi , we obtain the second order Taylor method:

w0 = α,
h2 ′
wi+1 = wi + hf (ti , wi ) + f (ti , wi ), i = 0, 1, . . . n − 1 .
2

4
From (6.5) we see that the second order Taylor method has local error
O(h3 ), and thus its global error is O(h2 ).

Example 6.4 Use the second order Taylor method with h = 0.25 to solve
the initial value problem

dy y
= 3t − , 1≤t≤2
dt t
y(1) = 2 .

6.4 Modified Euler method


Although the second order Taylor method provides higher accuracy than
Euler’s method, the requirement to differentiate f (t, y) makes it cumbersome
to use. Suppose, instead of differentiating f (t, y) exactly, we use a numerical
approximation to the derivative. This idea leads to the modified Euler
method:

w0 = α,
1
wi+1 = wi + (k1 + k2 ), i = 0, 1, . . . n − 1
2
where

k1 = hf (ti , wi ),
k2 = hf (ti + h, wi + k1 ) .

Example 6.5

(a) Use the first order forward difference approximation for f ′ in (6.5) to
deduce that
h
yi+1 = yi + [f (ti , yi ) + f (ti+1 , yi+1 )] + O(h3 ) .
2

(b) Use Euler’s method to approximate yi+1 to second order, and hence derive
the modified Euler method.

5
Example 6.6 Use the modified Euler method with h = 0.25 to solve the
initial value problem

dy y
= 3t − , 1≤t≤2
dt t
y(1) = 2 .

6.5 Runge-Kutta methods


(Bradie, Section 7.4)

6.5.1 Second order Runge-Kutta methods


Although the form given in the previous section is the usual “working form”
of the modified Euler method, to analyse the method theoretically it is prefer-
able to write it out in full:
1 1
wi+1 = wi + hf (ti , wi ) + hf (ti + h, wi + hf (ti , wi )) .
2 2
In fact, the modified Euler method is just one of a family of methods,
called the second order Runge-Kutta methods, that take the form

wi+1 = wi + c1 hf (ti , wi ) + c2 hf (ti + γ1 h, wi + γ2 hf (ti , wi )) .

Clearly, the modified Euler method corresponds to c1 = 1/2, c2 = 1/2,


γ1 = 1, γ2 = 1. It can be shown that any choices of c1 , c2 , γ1 , γ2 satisfying

1 1
c1 + c2 = 1, c2 γ 1 = , c2 γ 2 =
2 2
will lead to a valid second-order method. For example, another popular
method uses c1 = 0, c2 = 1, γ1 = 1/2, γ2 = 1/2. This is called the midpoint
method:

w0 = α,
wi+1 = wi + k2 , i = 0, 1, . . . n − 1

6
where

k1 = hf (ti , wi ),
 
h k1
k2 = hf ti + , wi + .
2 2

6.5.2 Higher order Runge-Kutta methods


By proceeding through some laborious algebra, it is possible to derive Runge-
Kutta methods that agree with the Taylor method to higher orders. By far
the most popular of all Runge-Kutta methods is the classical fourth order
method, usually referred to simply as RK4. It takes the following form:

w0 = α,
1
wi+1 = wi + (k1 + 2k2 + 2k3 + k4 ), i = 0, 1, . . . n − 1
6
where

k1 = hf (ti , wi),
 
h k1
k2 = hf ti + , wi + ,
2 2
 
h k2
k3 = hf ti + , wi + ,
2 2
k4 = hf (ti + h, wi + k3 ) .

Example 6.7 Use the classical fourth order Runge-Kutta method (RK4)
with h = 0.5 to solve the initial value problem

dy y
= 3t − , 1≤t≤2
dt t
y(1) = 2 .

7
6.6 Exercises
1. Solve the initial value problem

dy y
=1+ , 1≤t≤3
dt t
y(1) = 1

using Euler’s method with h = 0.5.

2. Solve the initial value problem

y ′ − ty 2 = 0, 0≤t≤1
1
y(0) =
2
using Euler’s method with h = 0.2.

3. Solve the initial value problem

yy ′ = et , 2≤t≤3
y(2) = 2

using Euler’s method with h = 1/3.

4. Repeat Question 1 using the second order Taylor method with h = 0.5.

5. Repeat Question 2 using the second order Taylor method with h = 0.2.

6. Repeat Question 3 using the second order Taylor method with h = 1/3.

7. Repeat Question 1 using the modified Euler method with h = 0.5.

8. Repeat Question 2 using the modified Euler method with h = 0.2.

9. Repeat Question 3 using the modified Euler method with h = 1/3.

10. Repeat Question 1 using the classical fourth order Runge-Kutta method
(RK4) with h = 1.

8
11. Repeat Question 2 using the classical fourth order Runge-Kutta method
(RK4) with h = 0.5.

12. Repeat Question 3 using the classical fourth order Runge-Kutta method
(RK4) with h = 1/3.

13. Consider the initial value problem

dy
= 2 sin(t) − y, y(0) = 1 .
dt
(a) Approximate y(0.2) using Euler’s method with h = 0.1.
(b) Approximate y(0.2) using the second order Taylor method with
h = 0.1.
(c) Approximate y(0.2) using the modified Euler method with h =
0.1.
(d) Approximate y(0.2) using the classical fourth order Runge-Kutta
method (RK4) with h = 0.2.

*14. Derive Euler’s method, including the order of the local error, by eval-
uating (6.2) at y = ti and applying the first order forward difference
approximation for dy
dt
.

*15. Derive Euler’s method, including the order of the local error, by inte-
grating (6.2) from t = ti to t = ti+1 and applying the left rectangle
rule.

*16. Derive the modified Euler method, including the order of the local
error, by integrating (6.2) from t = ti to t = ti+1 and applying the
trapezoidal rule.

*17. Derive the midpoint method, including the order of the local error, by
integrating (6.2) from t = ti to t = ti+1 and applying the midpoint rule.

You might also like