Solving differential equations

Chapter 12
Solving differential
equations
12.1 Introduction
In the previous chapters, we were introduced to differential equations. We saw that the verbal descriptions of the rate of change of a process (for example, the growth of a population
or the decay of a radioactive substance) can be expressed in the format of a differential
equation, and that the functions associated with such equations allow us to predict the behaviour of the process over time.
In this chapter, we will develop some of these ideas further. We will explore several
techniques for finding and verifying that a given function is a solution to a differential
equation. We will then examine a simple class of differential equations that have many
applications to processes of production and decay, and find their solutions. Finally we will
show how an approximation method provides for numerical solutions of such problems.
12.2 Given a function, check that it is a solution
In this section we concentrate on analytic solutions to a differential equation. By analytic
solution, we mean a “formula” in the form y = f (x) that satisfies the given differential equation. We have already seen in the previous chapter that we can check whether a
function satisfies a differential equation. (See Example 11.11.)
Suppose we encounter a new differential equation, and we are given a function that is
believed to satisfy that equation. We can always check and verify that this claim is correct
(or find it incorrect) by simple differentiation. Examples in this section demonstrate this
process.
219
220
Chapter 12. Solving differential equations
Section 12.2 Learning goals
1. Given a function, be able to check that whether that function does or does not satisfy
a given differential equation.
2. Be able to check whether a given function does or does not satisfy an initial condition.
Example 12.1 Show that the function y(t) = (2t + 1)1/2 is a solution to the differential
equation and initial condition
dy
1
= ,
dt
y
y(0) = 1.
Solution: First, we check the derivative, obtaining
d(2t + 1)1/2
1
1
1
dy(t)
=
= (2t + 1)−1/2 · 2 = (2t + 1)−1/2 =
= .
dt
dt
2
y
(2t + 1)1/2
Hence, the function satisfies the differential equation. Next, we examine the initial condition, and find that y(0) = (2 · 0 + 1)1/2 = 11/2 = 1. Hence the initial condition is also
satisfied.
Example 12.2 Consider the differential equation and initial condition
dy
= 1 − y,
dt
y(0) = y0 .
Show that the function y(t) = y0 e−t is not a solution to this differential equation, but that
the function y(t) = 1 − (1 − y0 )e−t is a solution.
Solution: (a) To check whether y(t) = y0 e−t is a solution, we differentiate this function,
obtaining
d[y0 e−t ]
dy
=
= −y0 e−t = −y "= 1 − y.
dt
dt
Thus the function does not satisfy the differential equation.
(b) We check the second function. Differentiating, we obtain
dy
d
de−t
= [1 − (1 − y0 )e−t ] = −(1 − y0 )
= −(1 − y0 )(−e−t ) = (1 − y0 )e−t .
dt
dt
dt
We ask whether this agrees with the RHS of the DE, which is 1 − y. We compute that
!
"
y(t) = 1 − (1 − y0 )e−t ⇒ 1 − y = 1 − 1 − (1 − y0 )e−t = (1 − y0 )e−t .
Hence we have RHS=LHS so the differential equation is satisfied. Next, let us show that
the initial condition is also satisfied. At time t = 0 we have that
y(0) = 1 − (1 − y0 )e0 = 1 − (1 − y0 ) · 1 = 1 − (1 − y0 ) = y0 .
Thus both the differential equation and the initial condition are satisfied.
12.3. Equations of the form y " (t) = a − by
221
Example 12.3 (Height of water draining out of a cylindrical container:) A cylindrical container with cross-sectional area A contains water. When a small hole of area a is opened
at its base, the water leaks out. It can be shown that height of water h(t) in the container
satisfies the differential equation
√
dh
(12.1)
= −k h.
dt
where √
k is a constant that depends on the size and shape of the cylinder and its hole:
a
k=A
2g, where g is the acceleration due to gravity. Show that the function
h(t) =
#$
t
h0 − k
2
%2
(12.2)
is a solution to the differential equation (12.1) and the initial condition h(0) = h0 .
Solution: By plugging in t = 0, we see that h(0) = h0 in (12.2). Thus, the initial condition
is satisfied. To show that the differential equation (12.1) is satisfied, we differentiate the
function in (12.2):
#
%2
#$
%#
%
#$
%
$
dh(t)
d $
−k
t
t
t
h0 − k
h0 − k
h0 − k
=2
·
= −k
= −k h(t).
=
dt
dt
2
2
2
2
Here we have used the power law and the chain rule, remembering
that h0 , k are con$
stants. Now we notice that, using (12.2), the expression for h(t) exactly matches what
we have computed for dh/dt. Thus, we have shown that the function in (12.2) satisfies
both the initial condition and the differential equation. Remark: The derivation of the differential equation from physical principles, and the calculation that discovers its solution is
discussed in a second semester calculus course.
As shown in Examples 12.1- 12.3, if we are told that a function is a solution to a
differential equation, we can check the assertion and verify that it is correct or incorrect.
A much more difficult task is to find the solution of a new differential equation from first
principles. In some cases, the technique of integration, learned in second semester calculus,
can be used. In other cases, some transformation that changes the problem to a more familiar one is helpful. (An example of this type is presented in Section 12.3.1). In many cases,
particularly those of so-called non-linear differential equations, it requires great expertise
and familiarity with advanced mathematical methods to find the solution to such problems
in an analytic form, i.e. as an explicit formula. In such cases, approximation and numerical
methods are helpful.
12.3 Equations of the form y % (t) = a − by
In this section we introduce an important class of differential equations that have many
applications in physics, chemistry, biology, and other applications. All share a similar
structure, namely all are of the form
dy
= a − by,
dt
y(0) = y0 .
(12.3)
222
Chapter 12. Solving differential equations
Methods for finding solutions to such differential equations are the same. We first introduce
a simple example of this type and show how a systematic process leads to the solution.
Them we examine a number of interesting applications to be explored in more detail.
Section 12.3 Learning goals
1. Learn how to reduce a differential equation of the form (12.3) to a simple decay
equation, and thereby find its solution.
2. Understand the example of Newton’s Law of Cooling (NLC), which is an equation
of the same type. Be able to find its solution and explain verbally what this solution
means.
3. Be able to use the solution to NLC to solve problems involving an object whose
temperature is changing over time.
4. Understand a variety of related examples, and be able to use the same methods to
solve and interpret these. (Examples include chemical production and decay, the
velocity of a skydiver, the concentration of drug in the blood, and others).
12.3.1
Reduction to a simpler differential equation
We will now introduce a “trick” that is often used by professional mathematicians: when
faced with a new problem whose solution is unknown, attempt to reduce the problem to
a simpler one (whose solution is easy or known). As shown in the next very important
example, we will “trade in” the new equation (12.3) for one that we already know how to
solve, namely to the simple decay equation (11.13). In the Example 12.4, the constants a, b
in (12.3) are 1. But the idea demonstrated here be used in the more general case as well.
Example 12.4 (An important idea) Suppose we are given the differential equation and
initial condition
dy
= 1 − y, y(0) = y0 .
(12.4)
dt
Determine the solutions to this differential equation.
Solution: It turns out that if we rewrite the DE (12.4) in terms of another variable, we can
easily solve it. This type of procedure is called transforming the variable. We will carry
out the following steps:
1. Replace the original variable (y) by one related to it (z) that simplifies the DE.
2. Solve the simpler DE in terms of z.
3. Change back to the original variable to get the desired solution in terms of y.
12.3. Equations of the form y " (t) = a − by
3.0
223
y
Solutions to the differential equation
dy/dt = 1 - y
time, t
0.0
0.0
2.0
Figure 12.1. Solutions to (12.4) are functions that approach the value y = 1
Step 1: Let z(t) = 1 − y(t). This will simplify the RHS of the differential equation. Then
the derivatives of z is related to that of y,
dz
dy
=− .
dt
dt
But by (12.4), dy/dt = 1 − y, so that
dz
= −(1 − y) = −z
dt
⇒
dz
= −z.
dt
We have arrived at a simpler equation, which we recognize as a decay equation (11.13),
expressed in terms of z. Observe, also, that the initial condition for y implies that at time
t = 0, we have z(0) = 1 − y(0) = 1 − y0 .
Step 2: We know the solution of the decay equation, so we can immediately write down
z(t) = z0 e−t
⇒
z(t) = (1 − y0 )e−t
where we have used the initial condition (stated in terms of the known quantity y0 ).
Step 3: It remains to rewrite the result in terms of the variable y. (We “transform” back to
the original variable.) Then
z(t) = (1 − y0 )e−t
⇒
1 − y(t) = (1 − y0 )e−t .
Rearranging, leads to
y(t) = 1 − (1 − y0 )e−t .
We have thereby arrived at the desired function that satisfies (12.4). Representative curves
in this family of solutions is shown in Fig. 12.1 for various initial values y0 .
224
Chapter 12. Solving differential equations
Example 12.5 Find the solution of (12.3) using a similar method.
Solution: Step 1: We define z(t) = a − by(t) and observe that
dz
dy
= −b
= −b(a − by) = −bz
dt
dt
⇒
dz
= −bz
dt
Furthermore, the initial condition for z is z(0) = a − by(0) = a − by0 = z0 .
Step 2: We can solve this equation (which is a simple decay equation once more), obtaining
z(t) = z0 e−bt = (a − by0 )e−bt .
Step 3: We complete the process by going back to the original variable, writing
a − by(t) = (a − by0 )e−bt ,
⇒
−by(t) = (a − by0 )e−bt − a
Isolating y(t), we have the desired solution,
'
a &a
− y0 e−bt .
y(t) = −
b
b
Detailed calculations are left as an exercise in Problem 4.
12.3.2
Newton’s law of cooling
Consider an object at temperature T (t) in an environment whose ambient temperature is
E. Depending on whether the object is cooler or warmer than the environment, the object
will heat up or cool down. From common experience we know that, after a long time, the
temperature of the object will have equilibrated with its environment.
The famous inventor of calculus, Isaac Newton formulated a hypothesis to describe
the rate of change of temperature. He assumed that
The rate of change of temperature T of an object is proportional to the difference
between its temperature and the ambient temperature, E.
To rephrase this statement in mathematical terms, we would write
dT
is proportional to (T (t) − E).
dt
This implies that the derivative dT /dt is some constant multiple of the term (T (t) − E).
However, the sign of that constant requires some discussion. Denote the constant of proportionality α temporarily, and suppose α ≥ 0. Let us check whether the differential equation
dT
= α(T (t) − E),
dt
12.3. Equations of the form y " (t) = a − by
225
makes physical sense. Suppose the object is warmer than its environment (T (t) > E).
Then T (t) − E) > 0 and α ≥ 0 implies that dT /dt > 0 which says that the temperature
of the object should get warmer! But this does not agree with our every-day experience: a
hot cup of coffee cools off in a chilly room! Hence α ≥ 0 cannot be correct. We conclude
that Newton’s Law of Cooling, written in the form of a differential equation, should read:
dT
= k(E − T (t)), where k > 0.
(12.5)
dt
(Notice that the sign of the term in braces has been switched). Generally, we are given the
temperature at some initial time T (0) = T0 and desire to predict T (t) for later time.
Example 12.6 Consider the temperature T (t) as a function of time. Solve the differential
equation for Newton’s law of cooling
dT
= k(E − T ),
dt
together with the initial condition T (0) = T0 .
Solution: As before, we transform the variable to reduce the differential equation to one
that we know how to solve. This time, we will select the new variable to be z(t) = E−T (t).
Then, by steps similar to previous examples, we find that
dz(t)
= −kz.
dt
(This is left as an exercise for the reader.) We also rewrite the initial condition in terms of
z, leading to z(0) = E − T (0) = E − T0 . After carrying out Steps 1-3 as before, we find
the solution, in terms of T (t),
T (t) = E + (T0 − E)e−kt .
(12.6)
In Figure 12.2 we show a family of curves of the form (12.6) for five different initial
temperature values. (We have set E = 10 and k = 0.2 for all these curves.) Next, we
interpret the behaviour of these solutions.
Example 12.7 Explain in words what the form of the solution (12.6) of Newton’s Law of
Cooling implies about the temperature of an object as it warms or cools.
Solution: We make the following remarks
• It is straightforward to verify that the initial temperature is T (0) = T0 . (Substitute
t = 0 into the solution (12.6).) Now let us examine the time dependence. Only
one term, e−kt depends on time. Since k > 0, this is an exponentially decaying
function, whose magnitude shrinks with time. Then the whole term that it multiplies,
(T0 − E)e−kt , continually shrinks. Hence we note that
T (t) = E+(T0 −E)e−kt
⇒
as t → ∞,
e−kt → 0,
so T (t) → E+0 = E.
(12.7)
Thus the temperature of the object always approaches the ambient temperature. This
is evident in the solution curves shown in Fig. 12.2.
226
Chapter 12. Solving differential equations
20
temperature
15
10
5
0
0
5
10
15
t
Figure 12.2. Temperature versus time for a cooling object
• We also observe that the direction of approach (decreasing or increasing) depends on
the sign of the constant (T0 − E). If T0 > E, the temperature approaches E from
above, whereas if T0 < E, the temperature approaches E from below.
• In the specific case that T0 = E, there is no change at all. T = E is a solution to
the differential equation that also satisfies dT /dt = 0. We refer to such a constant
solution as a steady state.
12.3.3
Using Newton’s Law of Cooling to solve a mystery
Now that we have a detailed solution to the differential equation representing Newton’s
Law of Cooling, we can apply it to making exact determinations of temperatures over time,
or of time at which a certain temperature was attained. The following example shows how
the solution can help us with an important determination of time of death.
Example 12.8 (Murder mystery:) It is a dark clear night. The air temperature is 10◦ C.
A body is discovered at midnight. Its temperature is then 27◦ C. One hour later, the body
has cooled to 24◦ C. Use Newton’s law of cooling to determine the time of death.
Solution: We will assume that the temperature of the person just before death is 37◦ C, i.e.
normal body temperature in humans. Letting the time of death be t = 0, this would mean
that T (0) = T0 = 37. We want to find how much time elapsed until the body was found,
i.e. the value of t at which the temperature of the body was 27◦ C. We are told that the
ambient temperature is E = 10, and we will assume that this was constant over the time
span being considered. Newton’s law of cooling states that
dT
= k(10 − T ).
dt
12.3. Equations of the form y " (t) = a − by
227
The solution to this equation is
T (t) = 10 + (37 − 10)e−kt .
We do not know the value of the constant k, but we have enough information to find it.
First, at discovery, the body’s temperature was 27◦ . Hence at time t
27 = 10 + 27e−kt
17 = 27e−kt .
⇒
Also at t + 1 (one hour after discovery), the temperature was 24◦ C, so
T (t + 1) = 10 + (37 − 10)e−k(t+1) = 24,
⇒
24 = 10 + 27e−k(t+1) .
Thus
14 = 27e−k(t+1) .
We have two separate equations for the two unknowns t and k. We can find both
unknowns from these. Taking the ratio of the two equations we obtained we get
# %
14
27e−k(t+1)
14
−k
= e . ⇒ −k = ln
= −0.194
=
−kt
17
27e
17
Thus we have found the constant that describes the rate of cooling of the body. To find the
time of death, t, we can use
# %
17
−kt
17 = 27e
⇒ −kt = ln
= −0.4626
27
so
0.4626
0.4626
=
= 2.384.
k
0.194
Thus the time of discovery of the body was 2.384 hours (i.e. 2 hours and 23 minutes) after
death, i.e. at 9:37 pm.
t=
12.3.4
Related applications and further examples
Having gained familiarity with specific examples, we now return to the general case. Summarizing the results of Example 12.5, we have found that
The differential equation and initial condition
dy
= a − by,
dt
has the solution
y(t) =
y(0) = y0
(12.8)
'
a &a
−
− y0 e−bt .
b
b
(12.9)
Suppose that a, b > 0 in Eqn. (12.8). Then we can summarize the behaviour of the
solutions (12.9) as follows:
228
Chapter 12. Solving differential equations
• The time dependence of (12.9) is contained in the term e−bt , which (for b > 0) is
exponentially decreasing. As time increases, t → ∞, the exponential term becomes
negligibly small, so y → a/b.
• If initially y(0) = y0 > a/b, then y(t) approaches a/b from above, whereas if
y0 < a/b, it approaches a/b from below.
• If initially y0 = a/b, there is no change at all (dy/dt = 0). Thus y = a/b is a steady
states of (12.8).
Newton’s Law of Cooling is one representative member of the class of differential
equations (12.8). We can see this by setting a = kE, b = k and T = y in (12.8) to get back
to Eqn. (12.5). Next, we describe other examples that share the same structure, and hence
a similar dynamic behaviour.
Friction and terminal velocity
The velocity of a falling object changes due to the force of gravity, but friction has an effect
of slowing down this acceleration. The differential equation satisfied by the velocity v(t)
of the falling object with friction is
dv
= g − kv
(12.10)
dt
where g > 0 is acceleration due to gravity and k > 0 is a constant that represents the effect
of friction due to air resistance.42 Usually, a frictional force is assumed to be proportional
to the velocity of the object, and to act in a direction that slows it down. (This accounts
for the negative sign in (12.10).) Parachutes operate on the principle of enhancing that
frictional force to damp out the acceleration of a skydiver. Hence, Eqn. (12.10) is often
called the skydiver equation.
Example 12.9 Use the general results for Eqn. (12.8) to write down the solution to the
differential equation (12.10) for the velocity of a skydiver given the initial condition v(0) =
v0 . Interpret your results in a simple verbal description of what happens over time.
Solution: Eqn. (12.10) is of the same form as Eqn. (12.8) , and has the same type of
solutions. We merely have to adjust the notation, by identifying
v(t) → y(t),
g → a,
k → b,
v0 → y0 .
Hence, without further calculation, we can conclude that the solution of (12.10) together
with the initial condition is:
'
g &g
v(t) = −
(12.11)
− v0 e−kt .
k
k
The velocity is initially v0 , and eventually approaches g/k which is the steady state or
terminal velocity for the object. Depending on the initial speed, the object will either slow
down (if v0 > g/k) or speed up (if v0 < g/k) as it approaches this constant velocity.
42 Eqn. (12.10) comes from a simple force balance: ma = F
gravity − Fdrag , and from the assumption that
Fdrag = µv, where µ > 0 is the “drag coefficient”. Dividing both sides by m and replacing a by dv/dt leads
to this equation, where k = µ/m.
12.4. Euler’s Method and numerical solutions
229
Chemical production and decay
A chemical reaction inside a fixed reaction volume produces a substance at a constant
rate Kin . A second reaction results in decay of that substance at a rate proportional to
its concentration. Let c(t) denote the time-dependent concentration of the substance, and
assume that time is measured in units of hours. Then, writing down a balance equation
leads to a differential equation of the form
dc
= Kin − γc.
dt
(12.12)
Here, the first term is the rate of production and the second term is the rate of decay. The
net rate of change of the chemical concentration is then the difference of the two. The
constants Kin > 0, γ > 0 represent the rate of production and decay. em Units of each
term in any equation have to match. For example, if the concentration c is measured in
units of milli-Molar (mM), then dc/dt has units of mM/hr, and hence Kin must have units
of mM/h and γ must have units of 1/hr.
Example 12.10 Write down the solution to the differential equation (12.12) given the initial condition c(0) = c0 . Determine the steady state concentration of the chemical.
Solution: We can understand the behaviour of these systems by translating our notation
from the general to the specific forms given above. For example,
c(t) → y(t),
Kin → a,
γ → b.
As before, we can write down the solution:
%
#
Kin
Kin
c(t) =
−
− v0 e−γt .
γ
γ
(12.13)
The steady state concentration is c = Kin /γ, and we expect that, regardless of the initial
condition, the chemical concentration will approach this level as time goes by.
As we have seen in this section, the behaviour found in the general case of the differential equation (12.3), can be reinterpreted in each of the specific situations of interest.
This points to one of the powerful aspects of mathematics, namely the ability to use results
in abstract general cases to solve a variety of seemingly unrelated scientific problems that
share the same mathematical structure.
12.4 Euler’s Method and numerical solutions
So far, we have explored ways of understanding the behaviour predicted by a differential
equation in the form of an analytic solution, namely a formula for the solution as a function
of time. In many cases, this is difficult without extensive training, or impossible even
for experts. Even if we can find such a solution, it may be inconvenient to determine its
numerical values at arbitrary times, or to interpret its behaviour.
For that reason, we add a method for computing an approximation for the desired
numerical solution with the aid of technology. The idea is to harness a computational
230
Chapter 12. Solving differential equations
device - computer, laptop, or calculator - to find numerical values of points along the solution curve, rather than attempting to determine the formula for the solution as a function of
time. Here we illustrate this process using a technique called Euler’s method, based on the
fact that derivatives can be approximated by finite differences.
Consider the general initial value problem (differential equation and initial condition) of the form
dy
= f (y), y(0) = y0 .
dt
Below, we explain how an approximate numerical solution is constructed using Euler’s
method.
Section 12.4 Learning goals
1. Understand how Euler’s method is based on approximating the derivative by the
slope of a secant line.
2. Understand the idea of a numerical solution and how this compares with an exact or
analytic solution.
3. Be able to use Euler’s method to calculate a numerical solution (using calculator,
spreadsheet, or your favourite software) to a given initial value problem.
To set up the recipe for generating successive values of the desired solution, we first
have to pick a “step size”, ∆t, and subdivide the t axis into discrete steps of that size: we
then have a set of time points t1 , t2 , . . . , spaced ∆t apart as shown in Figure 12.3. Our
procedure will be to start with the known initial value of y = y0 , and use it to generate the
value at the next time point (y1 ), then the next (y2 ), and so on. We will denote by yk the
value of the independent variable generated at the k’th time step.
Δt
time
0
t
1
t
2
t
3
t
4
t
5
Figure 12.3. The time axis is subdivided into steps of size ∆t.
To do so, will approximate the differential equation by a finite difference equation
dy
= f (y) approximated by
dt
yk+1 − yk
= f (yk ).
∆t
This approximation is reasonable only when ∆t, the time step size is small. (For small ∆t,
the slope of the secant line is a reasonable approximation for the derivative.) Rearranging
12.4. Euler’s Method and numerical solutions
231
this equation leads to a “recipe” (also called recursion relation) linking values of the
solution at successive time points,
yk+1 − yk
= f (yk ),
∆t
⇒
yk+1 = yk + ∆t · f (yk ).
(12.14)
How is this used in practice? We start with the known initial value, y0 . Then (setting the
index to k = 0 in (12.14)) we obtain
y1 = y0 + f (y0 )∆t.
The quantities on the right are known, so we can compute the value of y1 , i.e. the value of
the approximate “solution” at the time point t1 . We can then continue to generate the value
at the next time point in the same way, by approximating the derivative again as a secant
slope. This leads to
y2 = y1 + f (y1 )∆t.
The approximation so generated, leading to values y1 , y2 , . . . is called Euler’s method.
Applying this approximation repeatedly, leads to the iteration method, that is, the
repeated computation
y1 = y0 + f (y0 )∆t,
y2 = y1 + f (y1 )∆t,
..
.
yk+1 = yk + f (yk )∆t.
From this iteration, we obtain the approximate values of the function yk ≈ y(tk ) for as
many time steps as desired starting from t = 0 in increments of ∆t up to some final time
T of interest.
It is customary to use the following notation to refer to the true ideal solution and the
one that is actually produced by this approximation method:
• t0 = the initial time point, usually at t = 0.
• h = ∆t = common notations for the step size, i.e. the distance between the points
along the t axis.
• tk = the k’th time point. Since the points are just at multiples of the step size that
we have picked, it follows that tk = k∆t = kh.
• y(t) = the actual value of the solution to the differential equation at time t. This is
usually not known, but in the examples discussed in this chapter, we can solve the
differential equation exactly, so we have a formula for the function y(t). In most
hard scientific problems, no such formula is known in advance.
• y(tk ) = the actual value of the solution to the differential equation at one of the
discrete time points, tk . (Again, not usually known.)
232
Chapter 12. Solving differential equations
• yk = the approximate value of the solution obtained by Euler’s method. We hope
that this approximate value is fairly close to the true value, i.e. that yk ≈ y(tk ),
but there is always some error in the approximation. More advanced methods that
are specifically designed to reduce such errors are discussed in courses on numerical
analysis.
12.4.1
Euler’s method applied to population growth
We first illustrate how Euler’s method is used in a familiar example, that of unlimited
population growth.
Example 12.11 Apply Euler’s method to approximating solutions for the simple exponential growth model that was studied in Chapter 11,
dy
= ay,
dt
y(0) = y0
where a is a constant. (See Eqn 11.2.)
Solution: Subdivide the t axis into steps of size ∆t, starting with t0 = 0, and t1 = ∆t, t2 =
2∆t, . . . The first value of y is known from the initial condition,
y0 = y(0) = y0 .
We replace the differential equation by the approximation
yk+1 − yk
= ayk
∆t
⇒
yk+1 = yk + a∆tyk ,
k = 1, 2, . . .
In particular,
y1 = y0 + a∆ty0 = y0 (1 + a∆t),
y2 = y1 (1 + a∆t),
y3 = y2 (1 + a∆t),
and so on. At every stage, the quantity on the right hand side depends only on value of yk
that as already known from the step before.
Example 12.12 Use Euler’s method to find the solution to
dy
= −0.5y,
dt
y(0) = 100.
Use step size ∆t = 0.1 to approximate the solution for the first two time steps.
Solution: Euler’s method applied to this example would lead to
y0 =100.
y1 =y0 (1 + a∆t) = 100(1 + (−0.5)(0.1)) = 95,
y2 =y1 (1 + a∆t) = 95(1 + (−0.5)(0.1)) = 90.25.
Clearly, these kinds of repeated calculations are best handled on a spreadsheet or
similar computer software. In the next example, we illustrate that process.
12.4. Euler’s Method and numerical solutions
12.4.2
233
Euler’s method applied to Newton’s law of cooling
We apply Euler’s method to Newton’s Law of Cooling. A motivation for doing so is that
we can directly compare the approximate numerical solution generated by Euler’s method
to the true (analytic) solution that we have worked out in this chapter.
Example 12.13 (Newton’s law of cooling:) Consider the temperature of an object T (t)
in an ambient temperature of E = 10◦ . Assume that k = 0.2/min. Use the initial value
problem
dT
= k(E − T ), T (0) = T0
dt
to write down the the exact solution (12.6) in terms of the initial value T0 .
Solution: In this case, the differential equation has the form
dT
= 0.2(10 − T ),
dt
and its analytic solution, from (12.6), is
T (t) = 10 + (T0 − 10)e−0.2t .
(12.15)
Below, we use Euler’s method to compute a solution from each of several initial conditions,
T (0) = 0, 5, 15, 20 degrees.
Example 12.14 (Euler’s method applied to Newton’s law of cooling:) Write down the Euler’s method “recipe” for the approximate solution to the problem in Example 12.13.
Solution: Euler’s method approximates the differential equation by
Tk+1 − Tk
= 0.2(10 − Tk ).
∆t
or, in simplified form,
Tk+1 ≈ Tk + 0.2(10 − Tk )∆t.
Example 12.15 Use Euler’s recipe from Example 12.14 and time steps of size ∆t = 1.0 to
find a numerical solution to the the cooling problem. Use a spreadsheet for the calculations.
(Note that ∆t = 1.0 is not a “small step”, and we use it here only to illustrate the idea.)
Solution: The recipe to implement is
Tk+1 = Tk + 0.2(10 − Tk )∆t.
In Table 12.1, we show a typical example of the method with initial value T (0) = T0 = 0
and with the time step size ∆t = 1.0. The black dots represent the discrete values generated
234
Chapter 12. Solving differential equations
20.0
Euler's method
True solution
delta t = 1.0
0.0
0.0
time
tk
0.0000
1.0000
2.0000
3.0000
4.0000
5.0000
6.0000
7.0000
8.0000
approx solution
Tk
0.0000
2.0000
3.6000
4.8800
5.9040
6.7232
7.3786
7.9028
8.3223
exact soln
T (t)
0.0000
1.8127
3.2968
4.5119
5.5067
6.3212
6.9881
7.5340
7.9810
10.0
Table 12.1. Euler’s method applied to Newton’s law of cooling. The graph shows
the true solution (red) and the approximate solution (black)
by the Euler method, starting from a given initial condition. We show the four solutions
for the initial temperatures T0 = 0, 5, 15, 20 degrees. (The black curve is simply made up
of line segments linking the numerical solution.) On the same graph, we also show the
analytic solution (red curves) given by (12.15) with the same four initial temperatures. We
see that the black and red curves start out at the same points (since they both satisfy the
same initial conditions.) However, the approximate solution obtained with Euler’s method
is not identical to the true solution. The difference between the two (gap between the red
and black curves) is the numerical error in the approximation.
Exercises
235
Exercises
12.1. Water draining form a container: In Example 12.3, we verified that the function
(√
)2
h(t) =
h0 − k 2t is a solution to the differential equation (12.1). Based on the
meaning of the problem, for how long does this solution remain valid?
12.2. Verify that the function y(t) = 1 − (1 − y0 )e−t satisfies the initial value problem
(differential equation and initial condition) (12.4).
12.3. Consider the differential equation
dy
= a − by
dt
where a, b are constants.
(a) Show that the function
a
− Ce−bt
b
satisfies the above differential equation for any constant C.
y(t) =
(b) Show that by setting
C=
a
− y0
b
we also satisfy the initial condition
y(0) = y0 .
Remark: You have now shown that the function
&
a ' −bt a
e
+
y(t) = y0 −
b
b
is a solution to the initial value problem (i.e differential equation plus initial
condition)
dy
= a − by, y(0) = y0 .
dt
12.4. Steps in an example: Complete the algebraic steps in Example 12.5 to show that
the solution to Eqn. (12.3) can be obtained by the substitution z(t) = a − by(t).
12.5. Verifying a solution: Show that the function
y(t) =
1
1−t
is a solution to the differential equation and initial condition
dy
= y2,
dt
y(0) = 1.
Comment on what happens to this solution as t approaches 1.
12.6. For each of the following, show the given function y is a solution to the given differential equation.
236
Chapter 12. Solving differential equations
dy
= 3y, y = 2t3 .
dt
d2 y
(b)
+ y = 0, y = −2 sin t + 3 cos t.
dt2
d2 y
dy
(c)
−2
+ y = 6et , y = 3t2 et .
dt2
dt
12.7. Show the function determined by the equation 2x2 + xy − y 2 = C, where C is a
dy
constant and 2y "= x, is a solution to the differential equation (x−2y)
= −4x−y.
dx
12.8. Find the constant C that satisfies the given initial conditions.
(a) t ·
(a) 2x2 − 3y 2 = C, y|x=0 = 2.
(b) y = C1 e5t + C2 te5t , y|t=0 = 1 and
(c) y = C1 cos(t − C2 ), y|t= π2 = 0 and
dy
dt |t=0 = 0.
dy
π
dt |t= 2 = 1.
12.9. Friction and terminal velocity: The velocity of a falling object changes due to the
acceleration of gravity, but friction has an effect of slowing down this acceleration.
The differential equation satisfied by the velocity v(t) of the falling object is
dv
= g − kv
dt
where g is acceleration due to gravity and k is a constant that represents the effect
of friction. An object is dropped from rest from a plane.
(a) Find the function v(t) that represents its velocity over time.
(b) What happens to the velocity after the object has been falling for a long time
(but before it has hit the ground)?
12.10. Alcohol level: Alcohol enters the blood stream at a constant rate k gm per unit time
during a drinking session. The liver gradually converts the alcohol to other, nontoxic byproducts. The rate of conversion per unit time is proportional to the current
blood alcohol level, so that the differential equation satisfied by the blood alcohol
level is
dc
= k − sc
dt
where k, s are positive constants. Suppose initially there is no alcohol in the blood.
Find the blood alcohol level c(t) as a function of time from t = 0, when the drinking
started.
12.11. Check that the differential equation (12.5) has the right sign, so that a hot object
cools off in a colder environment.
12.12. Fill in the missing steps in the solution to Newton’s Law of Cooling in Example 12.6.
12.13. Newton’s Law of Cooling: Newton’s Law of Cooling states that the rate of change
of the temperature of an object is proportional to the difference between the temperature of the object, T , and the ambient (environmental) temperature, E. This leads
to the differential equation
dT
= k(E − T )
dt
Exercises
237
where k > 0 is a constant that represents the material properties and, E is the
ambient temperature. (We will assume that E is also constant.)
(a) Show that the function
T (t) = E + (T0 − E)e−kt
which represents the temperature at time t satisfies this equation.
(b) The time of death of a murder victim can be estimated from the temperature of
the body if it is discovered early enough after the crime has occurred. Suppose
that in a room whose ambient temperature is E = 20◦ C, the temperature
of the body upon discovery is T = 30◦ C, and that a second measurement,
one hour later is T = 25◦ C. Determine the approximate time of death. (You
should use the fact that just prior to death, the temperature of the victim was
37◦ C.)
12.14. A cup of coffee: The temperature of a cup of coffee is initially 100 degrees C. Five
minutes later, (t = 5) it is 50 degrees C. If the ambient temperature is A = 20
degrees C, determine how long it takes for the temperature of the coffee to reach 30
degrees C.
12.15. Newton’s Law of Cooling applied to data: The following data was gathered in
producing Fig. 2.1 for cooling milk during yoghurt production. According to Newton’s Law of Cooling, this data can be described by the formula
T = E + (T (0) − E) e−kt .
where T (t) is the temperature of the milk (in degrees Fahrenheit) at time t (in min),
E is the ambient temperature, and k is some constant that we will determine in this
problem.
time (min) Temp
0.0
190.0
0.5
185.5
1.0
182.0
1.5
179.2
2.0
176.0
2.5
172.9
3.0
169.5
3.5
167.0
4.0
164.6
4.5
162.2
5.0
159.8
(a) Rewrite this relationship in terms of the quantity Y (t) = ln(T (t) − E), and
show that Y (t) is related linearly to the time t.
(b) Explain how the constant k could be found from this converted form of the
relationship.
(c) Use the data in the table and your favorite spreadsheet (or similar software) to
show that the data so transformed appears to be close to linear. Assume that
the ambient temperature was E = 20◦ F.
238
Chapter 12. Solving differential equations
(d) Use the same software to determine the constant k by fitting a line to the transformed data.
12.16. Infant weight gain: During the first year of its life, the weight of a baby is given by
√
y(t) = 3t + 64
where t is measured in some convenient unit.
(a) Show that y satisfies the differential equation
dy
k
=
dt
y
where k is some positive constant.
(b) What is the value for k?
(c) Suppose we adopt this differential equation as a model for human growth.
State concisely (that is, in one sentence) one feature about this differential
equation which makes it a reasonable model. State one feature which makes it
unreasonable.
12.17. Lake Fishing: Fish Unlimited is a company that manages the fish population in a
private lake. They restock the lake at constant rate (To restock means to add fish to
the lake). N fishers are allowed to fish in the lake per day. The population of fish in
the lake, F (t) is found to satisfy the differential equation
dF
= I − αN F
dt
(12.16)
(a) At what rate is fish added per day according to Eqn. (12.16)? (Give value and
units.) What is the average number of fish caught by one fisher? (Give value
and units.) What is being assumed about the fish birth and mortality rates in
Eqn. (12.16)?
(b) If the fish input and number of fishers are constant, what is the steady state
level of the fish population in the lake?
(c) At time t = 0 the company stops restocking the lake with fish. Write down the
revised form of the differential equation (12.16) that takes this into account.
(Assume the same level of fishing as before.) How long would it take for the
fish to fall to 25% of their initial level?
(d) When the fish population drops to the level Flow , fishing is stopped and the
lake is restocked with fish at the same constant rate (Eqn (12.16), with α = 0.)
Write down the revised version of (12.16) that takes this into account. How
long would it take for the fish population to double?
12.18. Tissue culture: Cells in a tissue culture produce a cytokine (a chemical that controls
the growth of other cells) at a constant rate of 10 nano-Moles per hour (nM/h). The
chemical has a half-life of 20 hours. Write down a differential equation (DE) that
describes this chemical production and decay. Solve this DE assuming that at t = 0
there is no cytokine. [1nM=10−9M].
Exercises
239
12.19. Glucose solution in a tank: A tank that holds 1 liter is initially full of plain water.
A concentrated solution of glucose, containing 0.25 gm/cm3 is pumped into the
tank continuously, at the rate 10 cm3 /min and the mixture (which is continuously
stirred to keep it uniform) is pumped out at the same rate. How much glucose will
there be in the tank after 30 minutes? After a long time? (Hint: write a differential
equation for c, the concentration of glucose in the tank by considering the rate at
which glucose enters and the rate at which glucose leaves the tank.)
12.20. Pollutant in a lake:
(From the Dec 1993 Math 100 Exam) A lake of constant volume V gallons contains
Q(t) pounds of pollutant at time t evenly distributed throughout the lake. Water
containing a concentration of k pounds per gallon of pollutant enters the lake at a
rate of r gallons per minute, and the well-mixed solution leaves at the same rate.
(a) Set up a differential equation that describes the way that the amount of pollutant in the lake will change.
(b) Determine what happens to the pollutant level after a long time if this process
continues.
(c) If k = 0 find the time T for the amount of pollutant to be reduced to one half
of its initial value.
12.21. A sugar solution: Sugar dissolves in water at a rate proportional to the amount of
sugar not yet in solution. Let Q(t) be the amount of sugar undissolved at time t.
The initial amount is 100 kg and after 4 hours the amount undissolved is 70 kg.
(a) Find a differential equation for Q(t) and solve it.
(b) How long will it take for 50 kg to dissolve?
12.22. Leaking water tank: A cylindrical tank with cross-sectional area A has a small
hole through which water drains. The height of the water in the tank y(t) at time t
is given by:
√
kt 2
)
y(t) = ( y0 −
2A
where k, y0 are constants.
(a) Show that the height of the water, y(t), satisfies the differential equation
dy
k√
y.
=−
dt
A
(b) What is the initial height of the water in the tank at time t = 0 ?
(c) At what time will the tank be empty ?
(d) At what rate is the volume of the water in the tank changing when t = 0?
12.23. Find those constants a, b so that y = ex and y = e−x are both solutions of the
differential equation
y "" + ay " + by = 0.
12.24. Euler’s method: Solve the decay equation in Example (12.12) analytically (that
is, find the formula for the solution in terms of a decaying exponential) and then
compare your values to the approximate solution values y1 and, y2 computed with
Euler’s method.
240
Chapter 12. Solving differential equations
12.25. Comparing approximate and true solutions:
(a) Use Euler’s method to find an approximate solution to the differential equation
dy
=y
dx
with y(0) = 1. Use a step size h = 0.1 and find the values of y up to x =
0.5. Compare the value you have calculated for y(0.5) using Euler’s method
with the true solution of this differential equation. What is the error i.e. the
difference between the true solution and the approximation?
(b) Now use Euler’s method on the differential equation
dy
= −y
dx
with y(0) = 1. Use a step size h = 0.1 again and find the values of y up
to x = 0.5. Compare the value you have calculated for y(0.5) using Euler’s
method with the true solution of this differential equation. What is the error
this time?
12.26. Write out the first 3 steps of Euler’s method for the problem in Example 12.14.
12.27. Use the spreadsheet and Euler’s method to solve the differential equation shown
below:
dy/dt = 0.5y(2 − y)
Use a step size of h = 0.1 and show (on the same graph) solutions for the following
four initial values:
y(0) = 0.5, y(0) = 1, y(0) = 1.5, y(0) = 2.25
For full credit, you must include a short explanation of what you did (e.g. 1-2
sentences and whatever equations you implemented on the spreadsheet.)