Page - 123 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 123 -
Text of the Page - 123 -
4.2 SpreadingofDiseases 123
4.2.9 DiscontinuousCoefficients:AVaccinationCampaign
Whataboutmodelingavaccinationcampaign? Imagine that sixdaysafter theout-
breakof thedisease, the localhealthstation launchesavaccinationcampaign.They
reach out tomany people, say 10 times as efficiently as in the previous (constant
vaccination)case. If thecampaign lasts for10dayswecanwrite
p.t/D (
0:005; 6 24 t 15 24;
0; otherwise
Note thatwemustmultiply the t value by24 because t ismeasured in hours, not
days. In thedifferential equationsystem,pS.t/mustbe replacedbyp.t/S.t/, and
in this case we get a differential equation systemwith a term that is discontinu-
ous. This is usually quite a challenge inmathematics, but as long aswe solve the
equationsnumerically inaprogram,adiscontinuouscoefficient is easy to treat.
There are twoways to implement the discontinuous coefficientp.t/: through
a functionand throughanarray. Thefunctionapproach isperhaps theeasiest:
def p(t):
return 0.005 if (6*24 <= t <= 15*24) else 0
In thecode forupdating thearraysSandVweget a termp(t[n])*S[n].
Wecanalso letp.t/beanarrayfilledwithcorrectvaluesprior to thesimulation.
Thenwe need to allocate an array p of length N_t+1 and find the indices corre-
sponding to the timeperiodbetween6and15days. These indices are found from
the timepointdividedby t. That is,
p = zeros(N_t+1)
start_index = 6*24/dt
stop_index = 15*24/dt
p[start_index:stop_index] = 0.005
The p.t/S.t/ term in the updating formulas for S and V simply becomes
p[n]*S[n]. ThefileSIRV2.pycontainsaprogrambasedonfillinganarrayp.
The effect of a vaccinationcampaign is illustrated inFig. 4.14. All thedata are
as inFig.4.13 (left), except thatp is ten times stronger for aperiodof10daysand
pD0elsewhere.
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