Download Logistic Growth

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Inverse problem wikipedia , lookup

Theoretical ecology wikipedia , lookup

Relativistic quantum mechanics wikipedia , lookup

Plateau principle wikipedia , lookup

Perturbation theory wikipedia , lookup

Mathematical descriptions of the electromagnetic field wikipedia , lookup

Navier–Stokes equations wikipedia , lookup

Routhian mechanics wikipedia , lookup

Computational fluid dynamics wikipedia , lookup

Computational electromagnetics wikipedia , lookup

Transcript
Created by Claudia Neuhauser
Worksheet 4: Ordinary Differential Equations
Ordinary Differential Equations
Ordinary differential equations are equations of the form
(1)
dx
 f ( x, t ) with x(0)  x0
dt
On the left hand side is the derivative of the dependent variable x with respect to the
independent variable t. On the right hand side, there is a function that may depend on
both x and t. The independent variable t often represents time. In contrast to discrete time
equations of the form xt 1  f ( xt ) , where time t is discrete ( t  1, 2,... ), the independent
variable t in Equation (1) is a continuous variable, that is, it takes on real values, for
instance, t  [0, ) . In addition, we prescribe the initial value at time 0, namely x0. (The
initial condition could be stated for some other time but time 0 is quite commonly used.)
A differential equation is called ordinary if it involves only one independent variable.
We begin with autonomous differential equations. These are ordinary differential
equations where the right hand side of Equation (1) does not explicitly depend on the
independent variable t. They are thus of the form
(2)
dx
 f (x )
dt
where f(x) is some function. Examples of this type of equation are, for instance,
exponential growth dN / dt  rN or logistic growth, dN / dt  rN (1  N / K ) . In both
examples, the independent variable t represents time, and the dependent variable N
represents population size. Both differential equations model the growth of a population.
We discuss both of them in the following.
Exponential Growth
The differential equation for exponential growth with parameter r, where r  (, ) ,
and initial condition N (0)  N0 is given by
(3)
dN
 rN with N (0)  N 0
dt
To understand where this equation comes from, we look at the definition of a derivative
dN
N (t  t )  N (t )
 lim
dt t 
t
We see from this that the following approximation for t small holds:
1
Worksheet 4: Ordinary Differential Equations
N (t  t )  N (t )
 rN (t )
t
from which we conclude that
N (t  t )  N (t )  rN (t )t
or
N (t  t )  N (t ) 1  r t 
Rt
This now is in the form of discrete time exponential growth where each time step is of
length t .
We can also relate the discrete time and continuous time growth by starting with
discrete time growth, which is given by
Nt 1  RNt
At time 0, we assume that the population size is equal to N 0 . If we measured population
size every h units of time then every unit of time where we think of h as being a number
between 0 and 1, we would write for the dynamics of this population
Nt  h  Rh Nt
Note that the growth parameter has a subscript that indicates the length of the time step.
We can compute how much the population size changes from time step to time step,
namely
Nt h  Nt  Rh Nt  Nt   Rh  1 Nt
If we divide both sides by h and let h tend to 0, we arrive at
(4)
lim
h 0
Nt  h  Nt
R 1
 lim h
Nt
h

0
h
h
The left-hand side converges to the derivative of N with respect to t (provided the limit
exists), and the right-hand side converges to rNt if the limit exists and we denote
(5)
r  lim
h 0
2
Rh  1
h
Worksheet 4: Ordinary Differential Equations
Equation (4) together with Equation (5) then yields the ordinary differential equation
describing exponential growth as given by Equation (3).
To see why the differential equation in (3) models exponential growth, we solve it. That
is, we want to find a function N (t ) that satisfies Equation (3), including the initial
condition. To solve Equation (3), we use separation of variables followed by integration.

dN
 r  dt
N
Carrying out the integration, we find
ln N (t )  rt  C1
where C1 is the constant of integration. The following algebraic steps simplify the
expression
N (t )  exp rt  C1 
N (t )  exp C1 exp rt 
C1 rt
N (t )  
e
e

C
We can now incorporate the initial condition
N (0)  Ce 0  N 0  C  N 0
We thus find as the solution of (3)
N (t )  N 0 e rt
We see that the solution is the exponential function. If N 0  0 , then N(t), the population
size at time t, will be 0 as well. This is thus a constant solution of (1). Furthermore, if
r<0, then, for any initial population size, N(t) will approach 0 as time tends to infinity. If
r>0, then N(t) will go to infinity when N(0)>0.
We can use the symbolic toolbox in Matlab to solve differential equations. Enter into the
Command Window
clear
syms x t r
x=dsolve('Dx=r*x','x(0)=x0','t')
If you want to evaluate the solution, you need to convert the string x into a function. This
is done using the inline function
3
Worksheet 4: Ordinary Differential Equations
xsol=inline(char(x),'t','x0','r')
To find the solution when t  2, x0  0.5, r  2 , type into the Command Window
t=2;x0=0.5;r=2;
xsol(t,x0,r)
To plot the function, you need to evaluate the solution for different values of t and then
use the plot function. First, however, you need to tell Matlab that you want a vector
function:
xsol=inline(vectorize(char(x)),'t','x0','r')
We then generate values for the time vector:
t=0:0.1:10;
We can evaluate the function using the same command as before
xsol(t,x0,r);
Plotting is done as follows
plot(t,xsol(t,x0,r));xlabel('t');ylabel('x(t)');title('Exponential
Growth');
Logistic Growth
The differential equation for logistic growth with the two parameters r>0 and K>0
(6)
dN
N

 rN 1   with N (0)  N 0
dt
K

can also be solved explicitly using separation of variables followed by integration. It is
more complicated, though: Integration involves a partial fraction decomposition. The
solution of (6) is then given by
N (t ) 
K


1   K 1e rt
 N0 
provided N 0  0 . If N 0  0 , then N (t )  0 for all later times. We see that if N 0  K ,
then N (t )  K for all later times. There are thus two constant solutions for this equation,
namely 0 and K. Furthermore, N(t) will approach K as time tends to infinity for any
positive initial population size.
4
Worksheet 4: Ordinary Differential Equations
Numerical Methods for Solving Differential Equations
Many differential equations cannot be solved exactly. Numerical methods have been
developed to approximate solutions. Numerical analysis is a field in mathematics that is
concerned with developing approximate numerical methods and assessing their accuracy,
for instance for solving differential equations. We will discuss the most basic method, the
Euler method, explain the basic ideas behind this numerical method, and how to
implement it on a spreadsheet using the example of exponential and logistic growth.
Approximating the Solution of a Differential Equation
An initial value problem can be written as
(7)
dy
 f ( x, y ),
dx
y ( x0 )  y 0
We assume that f and f / y are continuous in a rectangle ( x, y) : a  x  b, c  y  d ,
which contains the point ( x0 , y0 ) . This then guarantees that (7) has a solution (x) in
some interval ( x0   , x0   ) where   0 .
If it is not possible to solve an initial value problem analytically, numerical
methods are employed. The idea is to use a discrete set of points, xn , n  0,1,2, , (for
instance, equally spaced points xn  x0  nh, n  0,1,2, , where h is a positive
constant), and then to find values yn so that yn approximates the solution (x) at the
points xn, that is,
 x n   y n
Euler’s Method
We consider the initial value problem
(8)
dy
 f ( x, y ),
dx
y ( x0 )  y 0
and assume it has a solution (x) in some interval ( x0   , x0   ) where   0 . The
simplest scheme for approximating the solution (x) is Euler’s method, which can be
implemented in a spreadsheet. Euler’s method is not the best method in the sense of
accuracy but is clearly the simplest. It is directly based on the definition of the derivative.
Recall that the definition of a derivative is
 ( x  h)   ( x )
h0
h
 ( x)  lim
5
Worksheet 4: Ordinary Differential Equations
provided the limit exists. When h is sufficiently small, we can write
( x  h)  ( x)  h ( x)  terms of order h 2


dy
 f ( x, y )
dx
We say that the error in approximation is of order h 2 . This means that the error between
the exact solution and the approximation tends to 0 like a constant times h 2 as h tends to
0.
This procedure leads to the approximation scheme
(9)
xn1  xn  h
y n1  y n  hf xn , y n , n  0,1,2,
This method is a first-order method since the error in each step is of order h 2 and the
1
total number of steps is of order , resulting in a global error of h.
h
Euler’s Method for Autonomous Differential Equations
An autonomous differential equation is of the form
dy
 f ( y)
dx
and we can write the initial condition as before, namely y( x0 )  y 0 . The approximation
scheme simplifies to
(10)
x n 1  x n  h
y n 1  y n  hf  y n , n  0,1,2,
Task 1:
Look at Equation (10) and the graph below: If x0  x and x1  x  h , find
y 0 , ( x0 ), y1 , and ( x1 ) in the following graph. Where in the graph is the error of
approximation we made in the first iteration of the approximation scheme?
6
Worksheet 4: Ordinary Differential Equations
Figure 1: Euler’s method
Exponential Growth and the Euler Approximation
We illustrate the iteration scheme for exponential growth. We choose a specific example,
namely we consider the initial value problem
(11)
dy
 2 y with
dx
y (0)  5
We know what the solution of (11) is, namely y  5 exp( 2 x) . We numerically solve (11)
using Euler’s method with h=0.1 in the time interval [0,0.5], and then check how well
this method performs. We have f ( y )  2 y . Then
x0  0
x1  x0  h  0  0.1  0.1
x 2  x1  h  0.1  0.1  0.2
x3  x 2  h  0.2  0.1  0.3
x 4  x3  h  0.3  0.1  0.4
x5  x 4  h  0.4  0.1  0.5
and
y0  5
y1  y 0  hf ( y 0 )  5  (
0.1)(2)(5)  6

h
f ( y0 )
y 2  y1  hf ( y1 )  6  (0.1)( 2)(6)  7.2
y 3  y 2  hf ( y 2 )  7.2  (0.1)( 2)(7.2)  8.64
y 4  y 3  hf ( y 3 )  8.64  (0.1)( 2)(8.64)  10.368
y 5  y 4  hf ( y 4 )  10.368  (0.1)( 2)(10.368)  12.4416
7
Worksheet 4: Ordinary Differential Equations
We summarize this in the following table. If h=0.1, then
x
0
0.1
0.2
0.3
0.4
0.5
y
Exact
Difference
5
6
7.2
8.64
10.368
12.4416
5
6.107014
7.459123
9.110594
11.1277
13.59141
0
0.107014
0.259123
0.470594
0.759705
1.149809
The third column contains the exact values, y  5 exp( 2 x) . The last error contains the
absolute error after each step, computed as |y-Exact|. We see that when h=0.1, the
numerical approximation is not very good after five steps. If we repeat the same
approximation with a smaller value for h, say h=0.01, the following table results for the
first five steps:
x
0
0.01
0.02
0.03
0.04
0.05
y
Exact
Difference
5
5.1
5.202
5.30604
5.412161
5.520404
5
5.101007
5.204054
5.309183
5.416435
5.525855
0
0.001007
0.002054
0.003143
0.004275
0.005451
Doing five steps only gets us to x=0.05. We can do more steps until we reach x=0.5. We
find that
x
0.5
y
Exact
Difference
13.45794
13.59141
0.133469
Choosing a smaller value for h resulted in a better approximation at x=0.5 but also
required more steps. One source of error in the approximation comes from the
approximation itself. Another source comes from rounding errors when we implement the
approximation on a computer. It is therefore not necessarily the case that smaller values
of h always improve the approximation.
Logistic Growth
Logistic growth is used to describe the growth of a population whose growth rate declines
with increasing population size. Its mathematical formulation is in terms of a differential
equation
(12)
dN
N

 rN 1  
dt
K

8
Worksheet 4: Ordinary Differential Equations
where N  N (t ) is the population size at time t. The parameter r is the intrinsic rate of
growth and the parameter K is called the carrying capacity. The population dynamics
evolve in continuous time, that is, changes occur at any time not just at discrete time
steps. This modeling scheme is appropriate when a population does not have discrete
breeding times. An example is the growth of Paramecium aurelia in a test tube
containing some culture medium with bacteria as food (Gause 1934).
Figure 2: Population size of Paramecium aurelia as a function of time. The data is from Gause (1934). A
logistic growth curve is fitted to the data. (Source: Case, 2000, page 104)
With the initial condition N(0)=N0, we found earlier that the solution is
(13)
N (t ) 
K
 K  N 0  rt
e
1  
 N0 
Task 2:
This task refers to logistic growth and uses Equations (12) and (13). Use a
spreadsheet to plot the following graphs for N0=5, r=2 and K=20: (a) the growth
rate dN/dt as a function of the population size N [use Equation (12)], (b) the per
capita growth rate dN/Ndt as a function of the population size N [divide both sides
of Equation (12) by N], and (c) the solution N(t) as a function of t [use Equation
(13)].
Task 3:
This task refers to logistic growth and uses Equation (13).Use a spreadsheet to plot
for r=2 and K=20 the solution N(t) in Equation (13) as a function of t for the
following initial conditions: (a) N0=1, (b) N0=20, and (c) N0=25. Plot all three graphs
in one coordinate system. Describe what you see.
9
Worksheet 4: Ordinary Differential Equations
Euler’s Method
The differential equation for logistic growth can be solved analytically. Now, however,
we will set up Euler’s method to approximate the solution of the logistic equation
dN
 g ( N ) with initial condition
dt
N (0)  N 0
N

with g ( N )  rN 1   , and then compare the approximate solution to the exact
K

solution in the computer lab exercises. As explained above, Euler’s method is based on
the definition of the derivative. If we choose a sufficiently small time step h, we can write
N (t  h)  N (t )
 g(N )
h
or, after rearranging the approximation,
N (t  h)  N (t )  hg ( N )
In the case of the logistic growth equation, we have t 0  0 , N (0)  N 0 , and Euler’s
scheme is
t n  nh
(14)
 N (t n ) 
N (t n1 )  N (t n )  hrN (t n )1 

K 

This can be used iteratively and thus implemented into a spreadsheet. Let’s see how the
first few steps work. Start with specifying the initial population size N0 and the two
parameters r and K. Then choose a step size h sufficiently small. The approximation can
be used to compute N(h)
(15)
N (0) 

N (h)  N (0)  hrN (0)1 

K 

This gives an approximation for N(h). Using N(h), we can compute N(h+h)=N(2h), then
N(2h+h)=N(3h), and so on.
Theoretically, the accuracy of this method improves with decreasing h. However,
as mentioned earlier, there are two important limitations: Decreasing h increases the
computing time and the cumulative errors due to rounding.
10
Worksheet 4: Ordinary Differential Equations
Task 4:
When h=1, Equation (15) becomes
(16)
N (0) 

N (1)  N (0)  rN (0)1 

K 

Compare this to the recursion of the discrete time logistic equation
(17)

 N 
N t 1  N t 1  R1  t 
K 


We discussed (17) in Worksheet 3. How is r in (16) related to R in (17)?
Equilibria and Stability
The two examples, exponential growth and logistic growth, introduced two important
concepts: constant solutions and long-term behavior. Constant solutions are called point
equilibria and the long-term behavior tells us something about the stability of these point
equilibria.
dx
 f (x ) are defined as the solutions
Point equilibria of a differential equation
dt
of f ( x)  0 . Point equilibria are the constant solutions of the differential equation.
Task 5:
Find all equilibria of (a) exponential growth and (b) logistic growth.
dx
 f (x ) . We say that
dt
x̂ is locally stable if the solution returns to x̂ after a small perturbation. Otherwise we
call x̂ unstable. There is a graphical and an analytical way to determine stability.
Suppose that x̂ is a point equilibrium of the differential equation
Graphical Analysis
For the graphical analysis, we graph f(x) as a function of x. The point equilibria are the
points of intersection of the graph with the horizontal axis. To determine stability, we
dx
 f (x ) behaves in a neighborhood of each point equilibrium (Figure 3).
check how
dt
11
Worksheet 4: Ordinary Differential Equations
f(x)
Locally stable
Unstable
x
Locally stable
Figure 3: Locally stability can be analyzed graphically. The arrows indicate whether x will increase or
decrease.
Analytical Analysis
The analytical analysis is based on linearization about an equilibrium. The linearization
of f(x) about the equilibrium x̂ is
f ( x)  
f ( xˆ )  f ( xˆ )x  xˆ 
0
A perturbation about the equilibrium x̂ can be written as z  x  xˆ . Now, since
dz dx

,
dt dt
we find
dz
 f ( xˆ ) z
dt
for z sufficiently small. Comparing this with exponential growth, it follows that x̂ is
locally stable if f ( xˆ )  0 , and unstable if f ( xˆ )  0 . When f ( xˆ )  0 , the linear
stability analysis is inconclusive. Looking at Figure 3 again, we can confirm that this
characterization agrees with the graphical analysis. We call f ( xˆ ) an eigenvalue.
12
Worksheet 4: Ordinary Differential Equations
Homework (Hand in on ____________________)
Step 1
Set up a spreadsheet to code up Euler’s method for exponential growth
dy
 2 y with
dx
y (0)  5
for step size h=0.1 and time interval [0,5]. This is Equation (11) and your result should
agree with what we obtained in the worksheet earlier. Paste the table in your report.
Step 2
Set up a spreadsheet to code up Euler’s method for logistic growth for the parameters
N(0)=5, r=2, and K=20, and step size h=0.1. Your spreadsheet should look like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
A
B
C
Logistic Growth: Euler's Method
D
E
Parameters
r
K
2
Time
0
0.1
0.2
0.3
0.4
0.5
N(0)
20
h
5
0.1
N(t)--Euler
N(t)--Solution
relative error
maximum error
5
5.75
6.569375
7.451683121
8.386743932
9.360717981
5
5.786715119
6.642399462
7.55733683
8.517935115
9.507337728
0
0.006344725
0.010993687
0.013980283
0.015401759
0.015421746
0.015421746
Enter the parameters as numbers in row 5. Enter “0” in cell A9. Enter “=$C$5” in cells
B9 and C9. The relative error is computed as “=ABS((C9-B9)/C9)” and this goes into
cell D9. Write “=A9+$D$5” in cell A10 and drag this cell down to row 109. The
approximate solution based on Euler’s method goes into cell B10:
“=B9+$D$5*$A$5*B9*(1-B9/$B$5)” and the exact solution goes into cell C10:
“=$B$5/(1+($B$5-$C$5)*EXP(-$A$5*A10)/$C$5)”. Drag both cells down to row 109.
Finally, to compute the maximum error, write “=MAX(D9:D109)” into cell E9.
Use Euler’s approximation to solve the logistic equation for this set of parameters
numerically. Plot both the numerical and the analytical solution into one coordinate
system for the time interval [0,10].
13
Worksheet 4: Ordinary Differential Equations
Step 3
By changing the step size by increments of 0.1 from 0.1 to 1.0 (i.e., 0.1, 0.2, 0.3, …, 1.0),
you can investigate how the accuracy of the solution is affected by the choice of the step
size. (Note that you showed in Task 4 that if h=1, the model becomes the discrete logistic
growth equation.) In your lab report, provide the graphs for the parameters N(0)=5, r=2,
and K=20, and h=0.3, 0.7, and 1.0 for the time interval [0,10]. Repeat the same but now
set r=2.8 and extend the time interval to [0,30]. Report any interesting observations.
Step 4
(a) You have now become familiar with difference and differential equations. Compare
the two modeling approaches and comment on similarities and differences addressing the
following issues.
 Provide one biological example for each modeling approach that illustrates the
difference between discrete time and continuous time modeling.
 How do you find equilibria in each of the two modeling approaches?
 How do you analyze stability of equilibria in each of the two modeling
approaches?
 How do you implement each modeling approach in EXCEL, including whether
the solution is exact or an approximation?
(b) When you look back over the models we have discussed in more detail, what aspects
of the models surprised you (if any)?
(c) Reflecting back on difference and differential equations, what do you still find
unclear?
14
Worksheet 4: Ordinary Differential Equations
Homework (Hand in ________________________)
Problem 1 (Stoichiometry):
(a) The nutrient content of a consumer (for instance, the percent nitrogen of the
consumer’s biomass) can range from reflecting the nutrient content of its food to being
constant. The former is referred to as absence of homeostasis, the latter as strict
homeostasis. A model for homeostatic regulation is provided in Sterner and Elser (2002).
The model relates consumer’s nutrient content (denoted by y) to its food’s nutrient
content (denoted by x) as follows:
dy
y

dx
x
where 0    1 is a constant. Solve the differential equation and relate θ to absence of
homeostasis and strict homeostasis.
(b) When phosphorus content of Daphnia was plotted against phosphorus content of its
algal food on a log-log plot, a straight line with slope 1/7.7 resulted (see Sterner and
Elser, 2002; data from DeMott et al., 1998). Find a differential equation that relates
phosphorus content of Daphnia to the phosphorus content of its algal food.
Problem 2 (Logistic Growth):
Assume that the size of a population evolves according to the continuous time, logistic
growth equation with intrinsic rate of growth r=1.5. Assume that the carrying capacity
K=100.
(a) Find the differential equation that describes the rate of growth of this population.
(b) Write a Matlab code to solve the differential equation symbolically.
(c) Find all equilibria, and discuss the stability of the equilibria using the graphical
approach.
(d) Find the eigenvalues associated with the equilibria (i.e., find f ( xˆ ) where x̂ denotes
the equilibrium), and use the eigenvalues to determine stability of the equilibria. Compare
your answers with your results in (b).
Problem 3 (A Simple Model of Predation):
Suppose N(t) denotes the size of a population at time t. The population evolves according
to the logistic growth equation, but, in addition, predation reduces the size of the
population so that the rate of change is given by
15
Worksheet 4: Ordinary Differential Equations
(18)
dN
N  9N

 N 1   
dt
 50  5  N
The first term on the right-hand side describes the logistic growth; the second term
describes the effect of predation.
(a) Set
N  9N

g ( N )  N 1   
 50  5  N
and graph g(N).
(b) Find all equilibria of (18).
(c) Use your graph in (a) to determine the stability of the equilibria found in (b).
(d) Use the analytical approach to determine the stability of the equilibria found in (b),
that is, calculate g ( Nˆ ) for all equilibria N̂ you found in (b).
References
DeMott, W.R., R.D. Gulati, and K. Siewertsen (1998) Effects of phosphorus-deficient
diets on the carbon and phosphorus balance of Daphnia magna. Limnol. Oceanogr. 43:
1147-1161.
Sterner, R.W. and J.J. Elser (2002) Ecological Stoichiometry: the Biology of Elements
from Molecules to the Biosphere. Princeton University Press.
16