Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 225 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 225 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 225 -

Bild der Seite - 225 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 225 -

8.3 SpreadingofDisease:ASystemofFirstOrderODEs 225 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 dt = 0.5 T = 20.0 u, t = ode_FE(f, exact_solution(0), dt, T) diff = abs(exact_solution(t) - u).max() tol = 1E-15 # Tolerance for float comparison success = diff < tol assert success Asameasureof theerror,wehaveheresimplyusedthemaximumerror(pickedout bya call tomaxandassigned todiff). Recall that test functionsshould start with the nametest_, have no arguments, andformulatethetestasabooleanexpressionsuccessthat isTrue if thetestpasses andFalse if it fails.Test functionsshouldmake the test asassert success (here successcanalso bea booleanexpressionas inassert diff < tol). Observethatwecannotcomparediff tozero,which iswhatwemathematically expect, because diff is a floating-point variable that most likely contains small rounding errors. Therefore, we must comparediff to zero with a tolerance, here 10−15. You are encouraged to do Exercise 8.3 where the goal is to make a test function for a verification based on comparison with hand-calculated results for a few time steps. 8.3 SpreadingofDisease:ASystemofFirstOrderODEs Our aim with this section is to show in detail how one can apply mathematics and programming to solve a system of first-order ODEs. We will do this as we investigate the spreading of disease. The mathematical model is now a system of three differential equationswith three unknownfunctions. To derive such a model, we can use mainly intuition, so no specific background knowledge of diseases is required. 8.3.1 SpreadingofFlu Imagineaboardingschoolout in thecountryside.Thisschool isasmall andclosed society. Suddenly,one or more of the pupils get the flu. We expect that the flu may spread quite effectively or die out. The question is how many of the pupils and the school’sstaffwillbeaffected.Somequitesimplemathematicscanhelpustoachieve insight into the dynamicsofhowthedisease spreads.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
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
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python