You are on page 1of 6

EA4 Lab 1 - Due Tuesday, 10/06/2015

In this lab you will learn how to use the Matlab program ode45 to obtain
numerical solutions to differential equations modeling population evolution.
The lab extends the population modeling discussed in sections 2.1 and 2.2 in
the text.
Let P (t) be the population of some species as a function of time t. One
model for the population evolution is the logistic equation discussed in the
text, (see equation (3) on page 81 in the fourth edition of the text).
P
dP
= k P (M P ) = kM P (1 ) .
M
dt

(1)

In (1) the term kM P represents what is called the natural birth rate of the
species (in this case positive) which depends largely on the genetic makeup
of the species and the external environment. The quadratic term k P 2
represents the effect of intraspecies competition, i.e., competition among the
species P for some scarce resource such as food, water, air or living space.
(Note that competition decreases the population, hence the minus sign.)
While the logistic equation (1) describes some aspects of population evolution, there are important environmental issues which are not described by
this equation. One such issue, discussed in the text (page 96 in the fourth
edition) is harvesting, where the population decreases by a fixed rate H,
P
dP
= kM P (1 ) H .
M
dt
While the text refers to harvesting, you can also think of this equation as
describing some mechanism other than intraspecies competition which depletes the population. Such mechanisms could be emigration, or as you will
consider in this lab, predation on the species P from some predator species.
In many of these applications, it is not realistic to have the depletion rate
be independent of the population, but rather you think of depletion per unit
population, i.e.,
dP
P
(2)
= kM P (1 ) P H .
M
dt
When the depletion is caused by predation from a predator species (2) is
itself not realistic, because you dont want the depletion rate to be just
proportional to P . Predators can get satiated - there is a limit to how much
1

they can eat - and you need some saturation term to limit the depletion for
large values of P . This is incorporated by a denominator in the depletion
term,
P
dP
P H
= kM P (1 )
,
(3)
M
dt
P + C
where k, M, H, C are constants. For the predator-prey application, you can
think of H as some mean value of the predator population and C as the value
of the prey population where the predation rate is reduced to H/2 . In this
lab you will analyze and solve (3).
Task 1.P has units of population and t has units of time. Thus, the left
hand side of (3) has units of population/time. Determine the units of the

four parameters k, M, H, C.
Task 2.In this task you will show how by a suitable rescaling of time
and population you can reduce the number of parameters from four to two.
Define P and t by
P = Pref P , t = tref t ,
where Pref and tref are reference populations and times, respectively and P
and t now have no units. Determine Pref and tref so that P (t) satisfies the
equation
P
dP
= P (1 P )
.
(4)
dt
P +C
Note that
Explicitly determine Pref , tref , and C in terms of k, M, H, C.

to convert the equation from t to t you will have to use the chain rule of
calculus, so if your memory of the chain rule is a little fuzzy, this would be
a good time to review it.
Task 3. In order to simplify your algebra, take C = 1 and determine all
nonnegative critical points of (4) and their stability for all values of 0.
For the stability, you might want to use the derivative test, but there will be
a transition value of where the derivative test will fail and you will have
to use other arguments to determine stability.
Task 4. While (4) is autonomous (and thus separable) and the right
hand side of (4) is just a rational function of P and so that the integral can
be done by partial fractions, the integration would be very difficult for most
students (and instructors). Thus, for the remainder of this lab you will solve
(4) numerically using the Matlab function ode45. In this name ode stands for
ordinary differential equation since you are dealing with ordinary rather
than partial derivatives. The meaning of the numbers 45 will be explained
2

to you when we get to numerics in class. A simple example of how to use


ode45 is posted on Canvas.
Next adapt the posted example to solve (4). Make the following computations:
1. Set = 0 so that you have just the logistic equation. Take P (0) = .5
and solve over the interval 0 t 100. Make a graph comparing your
solution with the exact solution (in the fourth edition this is on page
82). Note, if you did it right you would get two curves that lie on top of
each other. You will have to use different symbols linewidths or colors
to distinguish the two graphs.
2. Set = 0.2, take P (0) = 0.85 and solve (4) over the interval 0 t
100 and graph your solution. Explain what you expect (you should
compute the positive critical point) and why the graph looks strange
to you. You need not hand in this graph as you will fix it up right
now. What you are seeing is numerical errors. ode45 is an adaptive
method, something that we will discuss when we get to numerics. As
such, it tries to determine the solution to within a prescribed error
tolerance which it estimates. The ode45 template that we have posted
uses the Matlab default tolerance. This tolerance is not sufficient for
this problem. Matlab provides a function odeset which allows you to set
the tolerances for ode45. There are two tolerances, one for the relative
error (RelT ol) and one for the absolute error (AbsT ol), In this case
tightening RelT ol is sufficient, but set both of these two tolerances to
105 and run your program again. Make a graph of the two solutions
using different colors or symbols to differentiate the two curves and
explain what you have found. Referring to your analysis of the positive
critical point explain why you have confidence in this solution. (Note
that odeset has many more options, but these will be the only two
options that you need for this lab.)
Next set = 2 and run your program with the two tolerances varying
between 105 and 1012 and P (0) = 0.25. Plot the solution for tolerance of 1012 and explain why it is consistent with your analysis of the
critical points for = 2. When Matlab graphs the solution the vertical
axis should extend into negative territory. This is an indication that
numerical errors are generating unphysical negative values. Using the
Matlab min function compute the minimum of the solution and make
3

a table showing the minimum value and the tolerance. Explain the results in this table and why you believe the results are reasonable. Then
varying RelT ol and AbsT ol determine which of these tolerances is most
important in this case and explain from the nature of the solution why
this is reasonable.
Finally, set = 1, P (0) = 0.25 and solve (4) over the interval 0 t
200 . Set both tolerances to 1012 . Show that in this case when P is
small (4) can be approximated by
dP
= P 3 .
dt

(5)

Set P (0) = 0.5 and compare your ode45 solution for (4) with the exact
solution to (5) (make a graph of the two solutions). Explain why the
approach to P = 0 takes so much longer than when = 2 .
Task 5. As we stated above, for a predator-prey system, represents
the population of the predators. In realistic models the predator population
cannot be prescribed but must be determined from a coupled system involving both predator and prey species. Also, for many predator-prey system the
predator population will not be constant but will vary in time. Depending on
the progress of the course we may discuss such coupled systems later on, but
right now we have not yet discussed how to deal with coupled systems. As
an approximation you will treat as a prescribed time dependent function
and determine the behavior of P .
For this task define as
(t) = 1 + .25 cos(.025t) ,
set the time interval for the computation as 0 t 1600 and take the initial
condition P (0) = 0.5 . The first thing you should do is validate your program
in terms of numerical accuracy. Run your program with both tolerances set
to 107 , 108 , 109 , 1010 , 1011 and 1012 . Plot the solutions on the same
graph using different colors or symbols for the different tolerances. From the
behavior of the solution determine what is the minimum tolerance required
for you to have confidence in the solution. Take care in choosing the colors,
linewidths and symbols for the different curves in this figure so when you
describe your judgement as to what what minimum tolerance is necessary
for you to have confidence in the solution your conclusion will be absolutely
clear from the figure.
4

Next run your program with RelT ol = 107 and AbsT ol = 1012 and the
other way RelT ol = 1012 and AbsT ol = 107 and compare both solution
with your most trusted computation to ascertain which is the most important
tolerance for this particular problem. Then, by looking at the behavior of
the solution explain why your conclusion is reasonable. Include a figure of
these computations in your report.
Finally, run your program with both tolerances set to 1012 and plot
the solution together with (t) 1. (Your figure will be much clearer if
you neglect the constant term in plotting (t).) Interpreting (t) as the
population of the predators, explain why your results are reasonable. (No
knowledge of environmental engineering is needed for this explanation, just
look carefully at the figure and use your engineering intuition.)
Task 6. Write a report explaining your results. Your report should have
an introduction, where you set out the problem and what you expect to learn
from the lab, five sections for each of the tasks above and a conclusion as to
what you did in this lab, what you learned in terms of numerics and what
you learned in terms of population models.
Presentation counts for the lab reports and we strongly urge you to read
the lab criteria that we posted on Canvas. In order to help you get the best
grade that you can we are listing here some important points from the lab
criteria.
1. Lab reports must be completely typed.
2. Each figure must have labeled axes and a caption describing what is
shown in the graph. When there are multiple curves on a plot there
should be a legend distinguishing the different curves. Each figure needs
a figure number and must be referred to and discussed in the text of
the report. Generally Matlab plots look more professional if you use a
LineWidth of 2 rather than the default value. It is up to you to include
clear and easy to read figures in your report.
3. Reports should be clearly written, have correct grammar and you should
use a spellchecker.
4. Reports should address all issues raised in the lab but should be concise
and to the point rather than ramble.

5. Copies of all programs must be attached as an appendix to your report. Each program in the appendix must be specifically related to the
associated task.
6. Sometimes it is easier to get help on a Matlab function (for example the
plot program) by doing a google search rather than using the Matlab
help capability. You should keep this in mind as you approach the
different Matlab tasks in this (and subsequent) labs.
Grading Criteria
Labs will be graded out of 100.
1. Task 1 - 5
2. Task 2 - 10
3. Task 3 - 10
4. Task 4 - 15
5. Task 5 - 20
6. Task 6 (introduction and conclusion) - 20
7. Presentation - 20
There will be no part credit for Tasks 1-3. You should understand that
while we expect to adhere to this grading scheme, we have a minimum standard for presentation for the reports. A report so poorly written that it does
not reach the minimum standard will not be accepted and you will just get
a zero for the lab. In addition, if your programs for any of the tasks above
are wrong, so that they cannot support your conclusions, we will give a zero
for that task.

You might also like