238
8 Solving Ordinary Differential Equations
Fig. 8.15 The effect of vaccination: p = 0.0005
Fig. 8.16 The effect of vaccination: p = 0.0001
is usually quite a challenge in mathematics, but as long as we solve the equations
numerically in a program, a discontinuous coefficient is easy to treat.
There are two ways to implement the discontinuous coefficient p(t): through a
function and through an array. The function approach is perhaps the easiest:
def p(t):
return 0.005 if (6*24 <= t <= 15*24) else 0
Note the handy if-else construction in the return statement here. It is a one-line
alternative to, for example,
if (6*24 <= t <= 15*24):
return 0.005
Précédent

- 258/350

Suivant