Page - 232 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 232 -
Text of the Page - 232 -
232 8 SolvingOrdinaryDifferentialEquations
8.3.5 AbstractProblemandNotation
Whenwe hadaspecific differentialequationwith oneunknown,we quickly turned
toanabstractdifferentialequationwritteninthegenericformu′ =f(u,t).Werefer
to such a problem as a scalar ODE. A specific equation corresponds to a specific
choiceof the formulaf(u,t) involvinguand(optionally) t.
It is advantageous to also write a system of differential equations in the same
abstractnotation,
u′ =f(u,t),
but this time it isunderstoodthatu is avectorof functionsandf is alsovector.We
say thatu′ = f(u,t) is a vector ODE or system of ODEs in this case. For the SIR
modelwe introduce the two3-vectors,onefor theunknowns,
u= (S(t),I(t),R(t)),
andone for the right-handside functions,
f(u,t)= (−βSI,βSI−γI,γI).
Theequationu′ =f(u,t)meanssetting the twovectorsequal, i.e., thecomponents
mustbepairwiseequal.Sinceu′ = (S′,I′,R′), weget thatu′ =f implies
S′ =−βSI,
I′ =βSI−γI,
R′ =γI .
The generalized short notation u′ = f(u,t) is very handy since we can derive
numerical methods and implement software for this abstract system and in a
particular application just identify the formulas in the f vector, implement these,
andcall functionality that solves thedifferentialequationsystem.
8.3.6 ProgrammingtheFEScheme;theGeneralCase
InPythoncode, theForwardEuler step
un+1 =un+Δtf(un,tn),
beingascalar oravectorequation,canbecodedas
u[n+1] = u[n] + dt*f(u[n], t[n])
both in the scalar and vector case. In the vector case, u[n] is a one-dimensional
numpyarrayof lengthm+1 holding themathematicalquantityun, and the Python
functionfmust returnanumpyarrayof lengthm+1.Then theexpressionu[n] +
dt*f(u[n], t[n]) is anarrayplusa scalar timesanarray.
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