First Order
First Order
dy 2
= y, y(1) = 1, (2.1)
dt t
dy 2
= y + t2 , y(1) = 1, (2.2)
dt t
dx
= 2 sin 3t − 4x, x (0) = 0. (2.3)
dt
The Simulink models were provided in Figures 1.18, 1.22, and 1.6, respec-
tively.
In this chapter we solve a few more first order equations in the form of
applications. These will include growth and decay, Newton’s Law of Cool-
ing, pursuit curves, free fall and terminal velocity, the logistic equation,
and the logistic equation with delay.
Here we have denoted the birth rate as b and the mortality rate as m. This
gives the total rate of change of population as
dP
= bP − mP ≡ kP, (2.4)
dt
28 solving differential equations using simulink
where k = b − m.
Equation (2.4) is easily modeled in Simulink. All of the needed blocks
are under the Commonly Used Blocks group. We need an Integrator, Con-
stant, Gain, and a Scope block. The output from the Integrator can be
feed into a Gain control, which represents k, and the output from the
Gain, kP, can then be used as an input to the Integrator. We add the
Scope in order to plot the solution. The model is shown in Figure 2.1.
Note that a Constant block was added to provide an external input of the
initial condition.
The exact solution is easily found noting that Equation (2.4) is a separa-
ble equation. Rearranging the equation, its differential form is
dP
= k dt.
P
Integrating, we have
dP
Z Z
= k dt
P
first order differential equations 29
ln | P| = kt + C. (2.5)
| P(t)| = ekt+C
P(t) = ±ekt+C
= Aekt . (2.6)
P(t) = P0 ekt .
In the Simulink model, the initial value was given as P(0) = 10 and the
decay constant by k = −0.5. Therefore, the solution in Figure 2.2 is of the
function P(t) = 10e−0.5t .
Equation (2.4) is the familiar exponential model of population growth: Malthusian population growth.
dP
= kP.
dt
We obtained solutions exhibiting exponential growth (k > 0) or decay
(k < 0). This Malthusian growth model has been named after Thomas
Robert Malthus (1766-1834), a clergyman who used this model to warn
of the impending doom of the human race if its reproductive practices
continued. Later we modify this model to account for competition for
resources, leading to the logistic differential equation.
If you take your hot cup of tea, and let it sit in a cold room, the tea
will cool off and reach room temperature after a period of time. The law
of cooling is attributed to Isaac Newton (1642-1727) who was probably
the first to state results on how bodies cool.1 The main idea is that a body 1
Newton’s 1701 Law of Cooling is
at temperature T (t) is initially at temperature T (0) = T0 . It is placed in an approximation to how bodies cool
for small temperature differences
an environment at an ambient temperature of Ta . The goal is to find the (T − Ta T) and does not take into ac-
temperature at a later time, T (t). count all of the cooling processes. One
account is given by C. T. O’Sullivan,
We will assume that the rate of change of the temperature of the body Am. J. Phys (1990) p 956-960.
is proportional to the temperature difference between the body and its
surroundings. Thus, we have
dT
∝ T − Ta .
dt
The proportionality is removed by introducing a cooling constant,
dT
= −k( T − Ta ), (2.7)
dt
30 solving differential equations using simulink
where k > 0.
This differential equation can be solved by first rewriting the equations
as
d
( T − Ta ) = −k( T − Ta ).
dt
This now takes the form of exponential decay of the function T (t) − Ta .
The solution is easily found as
T (t) − Ta = ( T0 − Ta )e−kt ,
or
T (t) = Ta + ( T0 − Ta )e−kt .
Example 2.1. A cup of tea at 90o C cools to 85o C in ten minutes. If the
room temperature is 22o C, what is its temperature after 30 minutes?
Using the general solution with T0 = 90o C,
85 = T (10)
= 22 + 68e−10k
63 = 68e−10k
63
e−10k = ≈ 0.926
68
−10k = ln 0.926
ln 0.926
k = −
10
≈ 0.00764 min−1 .
T (t) = 22 + 68e−0.00764t .
T0
Integrator
20
Newton's Law of Cooling
Ta T' = - k (T-T0)
first order differential equations 31
Next we model Equation (2.7) in Simulink. The input for the Integrator
is simply −k( T − Ta ). We need to define the constants k and Ta . We will
externally input the initial condition, T (0) = T0 in the Integrator block.
The simple model is shown in Figure 2.3. In this case we set k = 0.1 s−1 ,
Ta = 20o C, and T0 = 60o C. Running the simulation for 100 s, we obtain the
solution shown in Figure 2.4.
How good is the solution? We can solve the problem by hand for this
set of parameters. However, we will take this opportunity to introduce
the idea of a subsystem and set up a model in which we can interactively
modify the constants and get Simulink to automatically provide the exact
solution for comparison.
3
Newton's Law of Cooling
T ambient
T' = - k (T-T0)
We begin by replacing the scope with an output block. The Out1 block
can be found in the Sink group. The input to the subsystem will be the Creating a subsystem.
three parameters, k, T0 , and Ta . Each of these constant blocks in Figure 2.3
will be replaced by an In1 block, found in the Sources group. In Figure 2.5
the three inputs and one output are now oval blocks.
Double-click each of the three input blocks, one at a time, and set the
Port Number of k, T0 , and Ta , to 1, 2, and 3, respectively. Finally, rename
each of these controls using the labels that make sense, such as k for k. In
32 solving differential equations using simulink
So, we can feed the values of the parameters in the model into a Fcn block
and output the exact solution for comparison. We will also need a time
value. So, we will need the Clock block as well.
60 T(0) T(t)
IC Scope
20 T ambient
Ta
Cooling System
The entire model is shown in Figure 2.8. The subsystem is labeled Cool-
ing System The top portion is a repetition of the Newton’s Law of Cooling
model implemented previously.
We have added a Fcn block from the User-Defined Functions group.
The input will be a vector containing all of the variables in the exact solu-
tion. This is accomplished by adding a Mux (or Multiplex) block. Double-
click the Mux block and set the number of inputs to 4.
Now, double-click the Fcn block and enter the exact solution in the form
u(1)+u(2)*exp(-u(3)*u(4))
first order differential equations 33
60 T(0) T(t)
IC Scope
20 T ambient
Ta
Cooling system
Exact Solution
f(u)
Fcn Scope1
Clock
Here we have assumed that the variables are fed into the Mux block in the
order Ta , T0 − Ta , k, and t. In Figure 2.8 one can see how the values are
routed into the Mux block.
The output can be attached to a second scope, as shown, or can be sub-
tracted from the output of the Cooling System block to show the closeness
of the two solutions. One can also send the output to MATLAB using the
To Workspace block.
ÿ(t) = − g. (2.8)
tive force, f (v) should oppose the motion. If the body is falling, then f (v)
should be positive. If the body is rising, then f (v) would have to be nega-
tive to indicate the opposition to the motion.
We will model the drag as quadratic in the speed, f (v) = bv2 .
Example 2.2. Solve the free fall problem with f (v) = bv2 .
The differential equation that we need to solve is
v̇ = kv2 − g, (2.10)
where k = b/m. Note that this is a first order equation for v(t).
Formally, we can separate the variables and integrate over time to
obtain Z v
dz
t+C = . (2.11)
kz2 − g
If we can do the integral, then we have a solution for v. We evaluate
this integral using Partial Fraction Decomposition.
In order to factor the denominator in the current problem, we
first have to rewrite the constants. We let α2 = g/k and write the
integrand as
1 1 1
= . (2.12)
kz2 − g k z2 − α2
Noting that
1 1 1 1
= − , (2.13)
kz2 − g 2αk z − α z + α
the integrand can be easily integrated to find
1 v−α
t+C = ln . (2.14)
2αk v+α
Solving for v, we have
1 − Ae2αkt
v(t) = α, (2.15)
1 + Ae2αkt
where A ≡ eC . A can be determined using the initial velocity by
inserting t = 0,
1−A
v (0) = α.
1+A
Then,
α − v0
A= .
α + v0
There are other forms for the solution in terms of a tanh function, which
the reader can determine as an exercise. One important conclusion is that
forqlarge times, the ratio in the solution approaches −1. Thus, v → −α =
− gk as t → ∞. This means that the falling object will reach a constant
terminal velocity.
Equation (2.10) can be modeled in Simulink. The model is shown in
Figure 2.9. The solution for k = 0.00159m−1 , which is found for the above
sample computation, is shown in Figure 2.10. Weq see that terminal velocity
g
is obtained and matches the predicted value, − k = −78 m/s.
first order differential equations 35
Constant1
Scope
0.00159 u2
( a, vt)
( x, y)
x
( a, 0)
Can the dog catch the cat? This would happen if there is a time
when y(0) = vt. Inserting x = 0 into the solution, we have y(0) =
avw
w2 − v2
= vt. This is possible if w > v.
first order differential equations 37
2 1 y'
xos 1
w xos
Integrator
Integrator1 Scope
0 0
Clock
Product y'(0) y(0)
9.000001
Constant
5.997
u(3)*u(2)*u(1)/(u(1)^2-u(2)^2) 6
Display
Fcn1
Analytic Solution
For the interested reader, we complete the solution of the problem by
noting that Equation (2.16) can be rewritten as a first order separable equa-
tion in the slope function z( x ) = y0 ( x ). Namely,
w vp
( a − x )z0 = 1 + z2 .
v x
Separating variables, we find
w dz dx
Z p Z
√ = ln(z + 1 + z2 ) .
v 1 + z2 a−x
dx
Z
= − ln | a − x | + c1 .
a−x
The left hand side takes a little extra work,2 or looking the integral to find 2
One can use trigonometric substitu-
tion. Let z = tan θ and dz = sec2 θ dθ.
Z
dz p Then, the method proceeds as follows:
√ = ln(z + 1 + z2 ) + c2 .
1 + z2 dz sec2 θ
Z Z
√ = √ dθ
1 + z2 1 + tan2 θ
Putting these results together, we have for x > 0,
Z
= sec θ dθ
p v = ln(tan θ + sec θ ) + c2
ln(z + 1 + z2 ) = ln x + C.
w
p
= ln(z + 1 + z2 ) + c2 .
v
0= ln a + C,
w
or C = − wv ln a.
38 solving differential equations using simulink
1 x wv x − wv
y0 = −
2 a a
Integrating,
" v
x 1+ w
v
x 1− w
#
a a a
y( x ) = − + k.
2 1 + wv 1 − wv
Since y( a) = 0, we can solve for the integration constant, k,
a 1 1 avw
k= v − v = 2 .
2 1− w 1+ w w − v2
dy
= by − my, (2.18)
dt
first order differential equations 39
where we had defined the birth rate as b and the mortality rate as m. If
these rates are constant, then we can define k = b − m and obtain the
familiar exponential model of population growth.
When more realistic populations get large enough, there is competition
for resources, such as space and food, which can lead to a higher mortality
rate. Thus, the mortality rate may be a function of the population size,
m = m(y). The simplest model would be a linear dependence, m = m̃ + cy.
The logistic model was first published
Then, the previous exponential model would take the form in 1838 by Pierre François Verhulst
(1804-1849) in the form
dy
= ky − cy2 , (2.19) dN
N
dt = rN 1 − ,
dt K
where k = b − m̃. This is known as the logistic model of population growth. where N is the population at time t, r is
Typically, c is small and the added nonlinear term does not kick in until the growth rate, and K is what is called
the carrying capacity. Note that in this
the population gets large enough.
model r = k = Kc.
Example 2.4. Show that Equation (2.19) can be written in the form
z0 = kz(1 − z)
y0 = ky − cy2
αz0 = αkz − cα2 z2 ,
or c
z0 = kz 1 − α z .
k
Thus, we obtain the result, z0 = kz(1 − z), if we pick α = kc .
The point of this derivation is to show that there is only one free param-
eter, k, and that many combinations of c and k in the original problem lead
to essentially the same solution up to rescaling.
We can model the logistic equation, y0 = ry(1 − y), with r = 1 and
y(0) = 0.1 in Simulink. The model is shown in Figure 2.14. Running the
model gives the solution in Figure 2.15. It shows the typical sigmoidal
curve bounded by the solutions y = 0 and y = 1.
Sometimes the rate of change does not immediately take place when
the system changes. This can be modeled using differential-delay equa-
tions. For example, when the resources are being depleted, the effects
might be delayed. So, a possible model would be the logistic equation with
delay,
y0 = ry(t)(1 − y(t − τ )),
where τ is a fixed delay time.
40 solving differential equations using simulink
Product 1-y
y' = r y (1-y)
1
Constant
The problem with trying to solve this model at time t is that we need
to know something about the solution for earlier times, y(t − τ ). One way
to tackle the problem is to specify the solution for times [0, τ ] and then
to solve the equation with delay using this starting value. So, if y = 2
initially, we could let y = 2 for [0, τ ].
The Simulink model is shown in Figure 2.16. A Switch block is used
to specify the starting values for times up to τ = 1. Then, the differential
equation solver takes over with a Delay block used to enter the delay term.
This model produces the solution in Figure 2.17.
first order differential equations 41
2
y' 1 y
Alpha >= 1
s
Integrator Scope
Clock
Switch to enter y=2
for t<=1
0
Solve y'=0
y