0% found this document useful (0 votes)
35 views16 pages

First Order

This document discusses first order differential equations including exponential growth and decay models as well as Newton's Law of Cooling. Exponential growth and decay models are presented and solved using Simulink. Newton's Law of Cooling model is also derived and solved as an example of how bodies cool over time.

Uploaded by

hadiakhalid.34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views16 pages

First Order

This document discusses first order differential equations including exponential growth and decay models as well as Newton's Law of Cooling. Exponential growth and decay models are presented and solved using Simulink. Newton's Law of Cooling model is also derived and solved as an example of how bodies cool over time.

Uploaded by

hadiakhalid.34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

2

First Order Differential Equations

We have seen how to solve simple first order differential equations


using Simulink. In particular we have solved initial value problems for the
equations

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.

2.1 Exponential Growth and Decay

The simplest differential equations are those governing growth


and decay. As an example, we will discuss population models.
Let P(t) be the population at time t. We seek an expression for the rate
dP
of change of the population, . Assuming that there is no migration
dt
of population, the only way the population can change is by adding or
subtracting individuals in the population. The equation would take the
form
dP
= Rate In − Rate Out.
dt
The Rate In could be due to the number of births per unit time and the
Rate Out by the number of deaths per unit time. The simplest forms for
these rates would be given by terms proportional to the population:

Rate In = bP and Rate Out = mP.

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.

Figure 2.1: Simulink model for expo-


-0.5 nential growth and decay. The initial
P' value, P(0) = 10, is set in the Constant
1 P block and k = −0.5 is set in the Gain.
Gain xos
Integrator Scope
10
Constant

The solution for exponential decay with P(0) = 10 and k = −0.5 is


shown in Figure 2.2. The simulation time was set at 10s.

Figure 2.2: Solution for the exponential


decay with P(0) = 10 and k = −0.5.
The simulation time was set at 10.

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)

Next, we solve for P(t) through exponentiation,

| P(t)| = ekt+C
P(t) = ±ekt+C
= Aekt . (2.6)

Here we have defined the arbitrary constant, A = ±eC .


If the population at t = 0 is P0 , i.e., P(0) = P0 , then the solution gives
P(0) = Ae0 = A = P0 . So, the solution of the initial value problem is

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.

2.2 Newton’s Law of Cooling

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,

T (t) = 22 + (90 − 22)e−k = 22 + 68e−kt ,

we then find k using the given information, T (10) = 85o C. We have

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 .

This gives the solution for this model as

T (t) = 22 + 68e−0.00764t .

Now we can answer the question. What is T (30)?

T (30) = 22 + 68e−0.00764(30) = 76o C.

Figure 2.3: Simulation model for New-


0.1 T' ton’s Law of Cooling, T 0 = −k ( T − Ta ),
-1
T (0) = T0. Here we set k = 0.1 s−1 ,
k 1 T
Product Gain Ta = 20o C, and T0 = 60o C.
s
60 xo Scope

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.

Figure 2.4: Solution of Newton’s Law of


Cooling example.

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.

Figure 2.5: Creating a subsystem for the


1 T' Newton’s Law of Cooling model.
k
-1
Product 1 T
Gain 1
s
T(t)
2 xo
T(0)
Integrator

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

Figure 2.6: Subsystem for Newton’s


1 k
Law of Cooling, T 0 = −k( T − Ta ),
k T (0) = T0.
2 T(0) T(t) 1
T(0) T(t)
3 T ambient
T ambient
Subsystem

Figure 2.5 we show the subsystem that we have created.


Now highlight the entire subsystem using CTRL-A. In the menu sys-
tem, look for Create Subsystem from Selection. This is under the menu
item Diagram and subitem Subsystem & Model Reference. Rearranging
the resulting subsystem, one has something like the subsystem block in
Figure 2.6. This is the equivalent of a black box with three inputs and one
output.
Next, we can make use of the subsystem just created. Replace the three
input ports with constant blocks. Rename the Constant blocks with the
parameter name and fill each block with a value. The output port can be
replaced with a Scope block, or any other form of output desired. This can
be seen in Figure 2.7.
Before finishing with this model, we will build in the exact solution.
Recall that the general solution can be written in terms of the parameters
as
T (t) = Ta + ( T0 − Ta )e−kt .

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.

Newton's Law of Cooling Figure 2.7: Using a user-created subsys-


T' = - k (T-T0)
tem for Newton’s Law of Cooling.
0.1 k

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

Newton's Law of Cooling Figure 2.8: Model of Newton’s Law of


T' = - k (T-T0)
Cooling, T 0 = −k ( T − Ta ), T (0) = T0,
0.1 k using the subsystem feature.
k

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.

2.3 Free Fall with Drag

Consider an object falling to the ground with air resistance? Free


fall is the vertical motion of an object solely under the force of gravity. It
has been experimentally determined that an object near the surface of the
Earth falls at a constant acceleration in the absence of other forces, such
as air resistance. This constant acceleration is denoted by − g, where g is
called the acceleration due to gravity. The negative sign is an indication
that we have chosen a coordinate system in which “up” is positive.
We are interested in determining the position, y(t), of a falling body as
a function of time. The differential equation governing free fall is have

ÿ(t) = − g. (2.8)

Note that we will occasionally use a dot to indicate time differentiation.


We need to model the air resistance. As an object falls faster and faster,
the resistive force becomes greater. This drag force is a function of the
velocity. The idea is to write Newton’s Second Law of Motion F = ma in
the form
mÿ = −mg + f (v), (2.9)
where f (v) gives the resistive force and mg is the weight. Note that this
applies to free fall near the Earth’s surface. Also, for f (v) to be a resis-
34 solving differential equations using simulink

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

v' Figure 2.9: Model for free fall with drag


9.8 1 v as described by v̇ = kv2 − g.
xos
g
0 Integrator

Constant1
Scope
0.00159 u2

k Math Free Fall with Drag


Function v' = kv^2 - g

Figure 2.10: Solution for free fall with


drag with k = 0.00159 starting from
rest.

2.4 Pursuit Curves

Another application that is interesting is to find the path that a


body traces out as it moves towards a fixed point or another moving body.
Such curves are know as pursuit curves. These could model aircraft or
submarines following targets, or predators following prey. For example, a
hawk follows a sparrow, a large fish chases a small fish, or a fox chases a
rabbit.
Example 2.3. A dog at point ( x, y) sees a cat traveling at speed v
along a straight line. The dog runs towards the cat at constant speed
w but always in a direction along line of sight between their posi-
tions. If the dog starts out at the point (0, 0) at t = 0, when the cat is
at ( a, 0), then what is the path the dog needs to follow? Will the dog
catch the cat?
We show the path in Figure 2.12. Let the cat’s path be along the
36 solving differential equations using simulink

y Figure 2.11: A dog at point ( x, y) sees a


cat at point ( a, vt) and always follows
the straight line between these points.

( a, vt)

( x, y)

x
( a, 0)

line x = a. Therefore, the cat is at position ( a, vt) at time t. The goal is


to find the dog’s path, ( x (t), y(t)), or y = y( x ).
First we consider the equation of the line of sight between the
points ( x, y) and ( a, vt). Considering that the slope of this line is the
same as the slope of the tangent to the path, y = y( x ), we have
vt − y
y0 = .
a−x
The dog is moving at a constant speed, w and the distance the dog
to travels s given by L = wt, where t is the running time from the
origin. The distance the dog travels is also given by the arclength of
the path between (0, 0) and ( x, y) :
Z xq
L= 1 + [y0 ( x )]2 dx.
0
vt−y
Eliminating the time using y0 = a− x , we have
Z xq
w
1 + [y0 ( x )]2 dx = (y + ( a − x )y0 ).
0 v
Furthermore, we can differentiate this result with respect to x to get
rid of the integral,
w
q
1 + [y0 ( x )]2 = ( a − x )y00 . (2.16)
v
This is the differential equation governing the dog’s pursuit. A
Simulink model of this problem is shown in Figure 2.12.
The full solution for the path is given by
" 1+ v  v#
x w x 1− w
a a avw
y( x ) = − a v + 2 .
2 1 + wv 1− w w − v2

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

Figure 2.12: Model forp the pursuit


curve, ( a − x )y00 = wv 1 + [y0 ( x )]2 ,
sqrt(1+u^2)
y(0) = 0, y0 (0) = 0, for w = 2 and
Fcn v = 1.
1
v

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

The integrals can be computed using standard methods from calculus.


We can easily integrate the right hand side,

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 .

Using the initial condition z = y0 = 0 and x = a at t = 0,

v
0= ln a + C,
w

or C = − wv ln a.
38 solving differential equations using simulink

Figure 2.13: Solution for the pursuit


curve.

Using this value for c, we find


p v v
ln(z + 1 + z2 ) = ln x − ln a
w w
x v
w
= ln
a
p x v
w
z+ 1 + z2 = . (2.17)
a
We can solve for z = y0 , to find

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

2.5 The Logistic Equation

In this section we will explore a nonlinear population model. Typ-


ically, we want to model the growth of a given population, y(t), and the
differential equation governing the growth behavior of this population is
developed in a manner similar to that done in the section on growth and
decay. Recall the simple population model from Section 2.1,

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)

which has only one parameter.


We carry this out by rescaling the population, y(t) = αz(t), where
α is to be determined. Inserting this transformation, we have

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.

2.6 The Logistic Equation with Delay

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

Logistic Equation Figure 2.14: Simulink model for the


logistic equation, y0 = ry(1 − y).
y' y
1 1
s
Gain Integrator Scope

Product 1-y
y' = r y (1-y)
1
Constant

Figure 2.15: Solution of the logistic


equation, y0 = ry(1 − y), with r = 1 and
y(0) = 0.1.

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

y(1-y(t-1)) 1-y(t-1) y(t-1)


Product
Logistic Equation with Delay Transport
Delay
y' = alpha y(t)(1-y(t-1)) 1
Constant
Figure 2.16: Model for the logistic
equation with delay, y0 = ry(t)(1 −
2.7 Exercises y(t − τ )).

1. Model the following first order differential equations in Simulink and


find the solutions for different initial conditions.
dy ex
a. = .
dx 2y
dy
b. = y2 (1 + t2 ).
dt p
dy 1 − y2
c. = .
dx x
d. xy0 = y(1 − 2y).
e. y0 − (sin x )y = sin x.
f. xy0 − 2y = x2 .
ds
g. + 2s = st2 .
dt
h. x 0 − 2x = te2t .
dy
i. + y = sin x,.
dx
dy 3
j. − y = x3 .
dx x
2. Consider the case of free fall with a damping force proportional to the
velocity, f D = ±kv with k = 0.1 kg/s.

a. Using the correct sign, consider a 50 kg mass falling from rest


at a height of 100m. Find the velocity as a function of time.
Does the mass reach terminal velocity?
b. Let the mass be thrown upward from the ground with an
initial speed of 50 m/s. Find the velocity as a function of time
as it travels upward and then falls to the ground. How high
does the mass get? What is its speed when it returns to the
ground?
42 solving differential equations using simulink

Figure 2.17: Solution of the logistic


equation with delay, y0 = ry(t)(1 −
y(t − 1)) for y = 2, t ∈ [0, 1].

3. A paratrooper, 322 lbs including munitions, jumps from 10,000 ft.


Model this free fall with air resistance f (v) = 15v2 in Simulink. First,
write down the free fall equation. Use the model to solve for v(t). Is
there a terminal velocity? Find the time to land and the impact velocity.

4. Model the following problem in Simulink: The temperature inside your


house is 70o F and it is 30o F outside. At 1:00 A.M. the furnace breaks
down. At 3:00 A.M. the temperature in the house has dropped to 50o F.
Assuming the outside temperature is constant and that Newton’s Law
of Cooling applies, determine when the temperature inside your house
reaches 40o F.

5. Model the following problem in Simulink: A body is discovered during


a murder investigation at 8:00 P.M. and the temperature of the body is
70o F. Two hours later the body temperature has dropped to 60o F in a
room that is at 50o F. Assuming that Newton’s Law of Cooling applies
and the body temperature of the person was 98.6o F at the time of death,
determine when the murder occurred.

You might also like