Seite - 107 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 107 -
Text der Seite - 107 -
4.1 PopulationGrowth 107
sumes that r dependson thesizeof thepopulation,N:
N.tC t/ N.t/D r.N.t//N.t/:
Thecorrespondingdifferential equationbecomes
N 0 D r.N/N :
ThereaderisstronglyencouragedtorepeatthestepsinthederivationoftheForward
Euler schemeandestablish thatweget
NnC1 DNnC tr.Nn/Nn;
whichcomputesaseasyas foraconstantr, sincer.Nn/ isknownwhencomputing
NnC1.Alternatively,onecanusetheForwardEulerformulaforthegeneralproblem
u0 Df.u;t/andusef.u;t/D r.u/uandreplaceubyN .
Thesimplestchoiceofr.N/ isa linearfunction,startingwithsomegrowthvalue
Nr anddeclininguntil thepopulationhas reached itsmaximum,M, according to the
available resources:
r.N/D Nr.1 N=M/:
In the beginning,N M and wewill have exponential growth eNrt, but asN
increases, r.N/ decreases, andwhenN reachesM, r.N/ D 0 so there is now
moregrowthand thepopulation remainsatN.t/DM. This linear choiceofr.N/
gives rise to amodel that is called the logistic model. The parameterM is known
as thecarrying capacityof thepopulation.
Let us run the logistic model with aid of the ode_FE function in the ode_FE
module. We chooseN.0/ D 100, t D 0:5month,T D 60months, r D 0:1,
andM D 500. The complete program, calledlogistic.py, is basically a call to
ode_FE:
from ode_FE import ode_FE
import matplotlib.pyplot as plt
for dt, T in zip((0.5, 20), (60, 100)):
u, t = ode_FE(f=lambda u, t: 0.1*(1 - u/500.)*u, \
U_0=100, dt=dt, T=T)
plt.figure() # Make separate figures for each pass in the loop
plt.plot(t, u, ’b-’)
plt.xlabel(’t’); plt.ylabel(’N(t)’)
plt.savefig(’tmp_%g.png’ % dt); plt.savefig(’tmp_%g.pdf’ % dt)
Figure 4.7 shows the resulting curve. We see that the population stabilizes
aroundM D 500 individuals. A corresponding exponential growthwould reach
N0e rt D100e0:1 60 40;300 individuals!
It is always interesting to seewhat happenswith large t values. Wemay set
t D 20 and T D 100. Now the solution, seen in Fig. 4.8, oscillates and is
hence qualitatively wrong, because one can prove that the exact solution of the
differential equation ismonotone. (However, there is a corresponding difference
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2016
- Sprache
- englisch
- Lizenz
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 248
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik