Professional Documents
Culture Documents
Orinary Differential Equations
Orinary Differential Equations
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.
dy y
= 3t − , y(1) = 2.
dt t
2
6.2 Euler’s method
(Bradie, Section 7.2)
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:
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 .
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].
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 .
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 .
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
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
y ′ − ty 2 = 0, 0≤t≤1
1
y(0) =
2
using Euler’s method with h = 0.2.
yy ′ = et , 2≤t≤3
y(2) = 2
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.
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.
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.