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 - 218 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 218 -

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

Text of the Page - 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
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