Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 110 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 110 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 110 -

Image of the Page - 110 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 110 -

110 4 SolvingOrdinaryDifferentialEquations 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 Recall that test functionsshouldstartwith thenametest_,havenoarguments,and formulate the test as a boolean expressionsuccess that isTrue if the test passes andFalse if it fails. Test functionsshouldmakethe testasassert success(here successcanalsobeabooleanexpressionas inassert diff < tol). Observethatwecannotcomparediff tozero,whichiswhatwemathematically expect, because diff is a floating-point variable that most likely contains small rounding errors. Therefore,wemust comparediff to zerowith a tolerance, here 10 15. Youare encouraged todoExercise4.2where thegoal is tomakea test function for a verification based oncomparisonwith hand-calculated results for a few time steps. 4.2 SpreadingofDiseases Our aimwith this section is to show in detail howonecan applymathematics and programmingto investigate spreadingofdiseases. Themathematicalmodel is now a system of three differential equationswith three unknown functions. To derive suchamodel,wecanusemainly intuition, sonospecificbackgroundknowledgeof diseases is required. 4.2.1 SpreadingofaFlu Imagineaboardingschoolout in thecountryside. Thisschool isasmallandclosed society. Suddenly, one ormoreof the pupils get a flu. Weexpect that the flumay spread quite effectively or die out. The question is howmany of the pupils and the school’s staffwill be affected. Some quite simplemathematics can help us to achieve insight into thedynamicsofhowthedisease spreads. Let themathematical functionS.t/ count howmany individuals, at time t, that have thepossibility to get infected. Here, tmaycounthours or days, for instance. These individuals make up a category called susceptibles, labeled as S. Another category, I, consists of the individuals that are infected. Let I.t/ count howmany there are in category I at time t. An individual having recovered from the disease is assumed togain immunity. There is also a small possibility that an infectedwill die. Ineithercase, the individual ismovedfromtheIcategory toacategorywecall the removedcategory, labeledwithR.We letR.t/count thenumberof individuals in theR category at time t. Those who enter theR category, cannot leave this category.
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
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