Seite - 154 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 154 -
Text der Seite - 154 -
154 4 SolvingOrdinaryDifferentialEquations
c) For the case in b), find through experimentation the largest value of twhere
the exact solution and the numerical solution byHeun’smethod cannotbedis-
tinguished visually. It is of interest to see how far off the curve the Forward
Euler method is whenHeun’s method can be regarded as “exact” (for visual
purposes).
Filename:ode_Heun.py.
Exercise4.4: Findanappropriate timestep; logisticmodel
Compute the numerical solution of the logistic equation for a set of repeatedly
halved time steps: tk D 2 k t, k D 0;1;:: :. Plot the solutions correspond-
ing to the last two time steps tk and tk 1 in the sameplot. Continuedoing this
untilyoucannotvisuallydistinguish the twocurves in theplot. Thenonehasfound
asufficiently small timestep.
Hint Extend the logistic.pyfile. Introduce a loop over k, write out tk, and
ask theuser if the loop is tobecontinued.
Filename:logistic_dt.py.
Exercise4.5: Findanappropriate timestep;SIRmodel
RepeatExercise4.4 for theSIRmodel.
Hint Import the ode_FE function from the ode_system_FEmodule and make
amodified demo_SIR function that has a loop over repeatedly halved time steps.
PlotS,I, andRversus time for the two last timestep sizes in the sameplot.
Filename:SIR_dt.py.
Exercise4.6:Modelanadaptivevaccinationcampaign
In the SIRVmodelwith time-dependent vaccination fromSect. 4.2.9,wewant to
test the effect of an adaptivevaccination campaignwherevaccination is offeredas
longashalf of thepopulation is notvaccinated. The campaign starts after days.
That is,pDp0 ifV < 12.S0CI0/and t > days,otherwisepD0.
Demonstrate the effect of this vaccination policy: choose ˇ, , and as in
Sect. 4.2.9, setpD0:001, D10days, andsimulate for200days.
Hint Thisdiscontinuousp.t/ functioniseasiest implementedasaPythonfunction
containing the indicatedif test. Youmayuse thefileSIRV1.pyas starting point,
butnote that it implementsa time-dependentp.t/viaanarray.
Filename:SIRV_p_adapt.py.
Exercise4.7:MakeaSIRVmodelwith time-limitedeffectofvaccination
Weconsider theSIRVmodel fromSect. 4.2.8, but now the effect of vaccination is
time-limited. After a characteristic period of time, , the vaccination is nomore
effectiveand individuals areconsequentlymovedfromtheVto theScategoryand
canbe infected again. Mathematically, this can bemodeled as an average leakage
1V from the V category to the S category (i.e., a gain 1V in the latter).
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2016
- Sprache
- englisch
- Lizenz
- CC BY-NC 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 248
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik