Page - 238 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 238 -
Text of the Page - 238 -
238 8 SolvingOrdinaryDifferentialEquations
Fig. 8.15 The effect ofvaccination:p=0.0005
Fig. 8.16 The effect ofvaccination:p=0.0001
is usually quite a challenge in mathematics, but as long as we solve the equations
numerically ina program,adiscontinuouscoefficient is easy to treat.
There are two ways to implement the discontinuous coefficientp(t): through a
functionand throughanarray.The functionapproachisperhaps theeasiest:
def p(t):
return 0.005 if (6*24 <= t <= 15*24) else 0
Note the handyif-else construction in the return statement here. It is a one-line
alternative to, forexample,
if (6*24 <= t <= 15*24):
return 0.005
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