Seite - 218 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Bild der Seite - 218 -
Text der Seite - 218 -
218 8 SolvingOrdinaryDifferentialEquations
Note thecompactassignment statement
numerical_sol = ’bo’ if N_t < 70 else ’b-’
This is a one-linealternative to, e.g.,
if N_t < 70:
numerical_sol = ’bo’
else:
numerical_sol = ’b-’
Let us demonstrate a simulation where we start with 100 animals, a net growth
rate of 10% (0.1) per time unit, which can be 1 month, and t ∈ [0,20]months. We
may first tryΔt of half a month (0.5), which impliesNt = 40. Figure 8.6 shows
the results. The solid line is the exact solution, while the circles are the computed
numericalsolution.Thediscrepancyisclearlyvisible.What ifwemakeΔt 10times
smaller?TheresultisdisplayedinFig.8.7,wherewenowuseasolidlinealsoforthe
numericalsolution(otherwise,400circleswouldlookverycluttered,sotheprogram
hasa test onhowto display the numerical solution,eitherascirclesora solid line).
We can hardly distinguish the exact and the numerical solution. The computing
time is also a fraction of a second on a laptop, so it appears that the Forward Euler
method is sufficiently accurate for practical purposes. (This is not always true for
large,complicatedsimulationmodelsinengineering,somoresophisticatedmethods
maybeneeded.)
It is also of interest to see what happens if we increase Δt to 2 months. The
results inFig. 8.8 indicate that this is an inaccuratecomputation.
Fig. 8.6 Evolutionof a population computed with timestep 0.5 month
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