Seite - 239 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Bild der Seite - 239 -
Text der Seite - 239 -
8.4 Oscillating1DSystems:ASecondOrderODE 239
Fig. 8.17 The effect of a vaccination campaign
else:
return 0
In the codeforupdating thearraysSandV,we thengeta termp(t[n])*S[n].
Alternatively,we can instead letp(t)be an array filled with correct valuesprior
to thesimulation.Thenwe need to allocate an arraypof lengthN_t+1andfind the
indices corresponding to the time period between 6 and 15 days. These indices are
foundfromthe time pointdividedbyΔ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.pycontainsa programbasedonfillingan arrayp.
The effect of a vaccination campaign is illustrated in Fig. 8.17. All the data are
as inFig.8.15,except thatp is ten timesstronger foraperiodof10daysandp=0
elsewhere.
8.4 Oscillating1DSystems:ASecondOrderODE
Numerous engineering constructions and devices contain materials that act like
springs. Such springs give rise to oscillations, and controlling oscillations is a key
engineeringtask. We shallnowlearn to simulateoscillatingsystems.
Asalways,westartwith thesimplestmeaningfulmathematicalmodel,whichfor
oscillations is a second-orderdifferentialequation:
u′′(t)+ω2u(t)=0, (8.40)
Programming for Computations – Python
A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
- Titel
- Programming for Computations – Python
- Untertitel
- A Gentle Introduction to Numerical Simulations with Python 3.6
- Band
- Second Edition
- Autoren
- Svein Linge
- Hans Petter Langtangen
- Verlag
- Springer Open
- Datum
- 2020
- Sprache
- englisch
- Lizenz
- CC BY 4.0
- ISBN
- 978-3-319-32428-9
- Abmessungen
- 17.8 x 25.4 cm
- Seiten
- 356
- Schlagwörter
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Kategorie
- Informatik