Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 222 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 222 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 222 -

Image of the Page - 222 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 222 -

222 8 SolvingOrdinaryDifferentialEquations Thecorrespondingdifferentialequationbecomes N′ = r(N)N . Thereaderisstronglyencouragedtorepeatthestepsin thederivationoftheForward Euler schemeandestablish thatwe get Nn+1 =Nn+Δtr(Nn)Nn, whichcomputesaseasy as fora constant r, since r(Nn) is knownwhencomputing Nn+1.Alternatively,onecanuse theForwardEulerformulafor thegeneralproblem u′ =f(u,t)andusef(u,t)= r(u)uand replaceubyN. Thesimplestchoiceofr(N) isa linearfunction,startingwithsomegrowthvalue r¯ and declininguntil the populationhas reached its maximum,M, according to the available resources: r(N)= r¯(1−N/M). In the beginning, N M and we will have exponential growth er¯t, but as N increases, r(N) decreases, and whenN reachesM, r(N)= 0 so there is no more growth and the population remains atN(t)=M. This linear choice of r(N)gives rise to a model that is called the logistic model. The parameterM is known as the carryingcapacityof thepopulation. Letusrunthelogisticmodelwithaidoftheode_FEfunction.WechooseN(0)= 100, Δt = 0.5 month, T = 60 months, r = 0.1, and M = 500. The complete program,calledlogistic.py, is basicallya call toode_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’.format(dt)) plt.savefig(’tmp_{:g}.pdf’.format(dt)) Figure8.9showstheresultingcurve.Weseethat thepopulationstabilizesaround M = 500 individuals. A corresponding exponential growth would reachN0ert = 100e0.1·60 ≈40,300individuals! What happens if we use “large” Δt values here? We may set Δt = 20 and T = 100. Now the solution, seen in Fig. 8.10, oscillates and is hence qualitatively wrong,because one can prove that the exact solution of the differential equation is monotone.
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python