Seite - 224 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Bild der Seite - 224 -
Text der Seite - 224 -
224 8 SolvingOrdinaryDifferentialEquations
Remarkonthe worldpopulation
Thenumberofpeopleontheplanet(http://en.wikipedia.org/wiki/Population_
growth)followsthemodelN′ = r(t)N,wherethenetreproductionr(t)varies
with time and has decreased since its top in 1990. The current world value
of r is 1.2%, and it is difficult to predict future values. At the moment, the
predictions of the world population point to a growth to 9.6 billion before
declining.
This example shows the limitation of a differential equation model: we
need to know all input parameters, including r(t), in order to predict the
future. It is seldom the case that we know all input parameters. Sometimes
knowledgeofthesolutionfrommeasurementscanhelpestimatemissinginput
parameters.
8.2.7 Verification:ExactLinearSolutionoftheDiscrete
Equations
Howcan we verify that the programmingof an ODE model is correct?One way, is
tocomputeconvergencerateswith asolverandconfirmthat the ratesareaccording
to expectations. We address convergence rates for ODE solvers later (in Sect. 8.5)
andwill thenshowhowacorrespondingtest functionfor theode_FEsolvermaybe
written.
The best verification method, however, is to find a problem where there are no
unknown numerical approximation errors, because we can then compare the exact
solutionof the problemwith the resultproducedbyour implementationandexpect
the difference to be within a very small tolerance. We shall base a unit test on this
idea and implement a corresponding test function (see Sect. 6.6.4) for automatic
verificationofour implementation.
It appears that most numerical methods for ODEs will exactly reproduce a
solution u that is linear in t. We may therefore set u = at + b and choose any
f whose derivative is a. The choicef(u,t) = a is very simple, but we may add
anythingthat is zero,e.g.,
f(u,t)=a+(u−(at+b))m.
This is a validf(u,t) for any a, b, andm. The corresponding ODE looks highly
non-trivial,however:
u′ =a+ (u−(at+b))m.
Using the generalode_FE function in ode_FE.py, we may write 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."""
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python 3.6
- Band
- Second Edition
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2020
- Sprache
- englisch
- Lizenz
- CC BY 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 356
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik