Seite - 109 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 109 -
Text der Seite - 109 -
4.1 PopulationGrowth 109
Remarkontheworldpopulation
Thenumberofpeopleon theplanet2 follows themodelN 0 D r.t/N ,where the
net reproduction r.t/ varieswith time and has decreased since its top in 1990.
Thecurrentworldvalueof r is 1.2%,and it is difficult topredict futurevalues3.
At themoment, thepredictionsof theworldpopulationpoint to agrowth to9.6
billionbeforedeclining.
This example shows the limitationof adifferential equationmodel: weneed
toknowall input parameters, including r.t/, in order to predict the future. It is
seldomthecase thatweknowall inputparameters. Sometimesknowledgeof the
solution frommeasurementscanhelpestimatemissing inputparameters.
4.1.7 Verification:ExactLinearSolutionoftheDiscreteEquations
Howcanwe verify that the programming of anODEmodel is correct? The best
method is tofindaproblemwhere there arenounknownnumerical approximation
errors, becausewecan thencompare theexact solutionof theproblemwith the re-
sult producedbyour implementationand expect thedifference to bewithin avery
small tolerance.Weshall base aunit test on this ideaand implementacorrespond-
ing test function (seeSect. 3.4.4) forautomaticverificationofour implementation.
It appears thatmostnumericalmethods forODEswill exactly reproduceasolu-
tionu that is linear in t.WemaythereforesetuDatCb andchooseanyf whose
derivative isa. The choicef.u;t/ D a is very simple, butwemay add anything
that is zero, e.g.,
f.u;t/DaC.u .atCb//m:
This is a validf.u;t/ for anya, b, andm. The correspondingODE looks highly
non-trivial, however:
u0 DaC.u .atCb//m:
Using the generalode_FE function in ode_FE.py,wemaywrite a proper test
functionas follows (infiletest_ode_FE_exact_linear.py):
def test_ode_FE():
"""Test that a linear u(t)=a*t+b is exactly reproduced."""
def exact_solution(t):
return a*t + b
def f(u, t): # ODE
return a + (u - exact_solution(t))**m
a = 4
b = -1
m = 6
2http://en.wikipedia.org/wiki/Population_growth
3http://users.rcn.com/jkimball.ma.ultranet/BiologyPages/P/Populations.html
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