Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - 275 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 275 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 275 -

Image of the Page - 275 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 275 -

8.6 Exercises 275 as long as half of the population is not vaccinated. The campaign starts after Ξ” days. That is, p = p0 if V < 12(S0 + I0) and t > Ξ” days, otherwise p=0. Demonstrate the effect of this vaccination policy: choose Ξ², Ξ³ , and Ξ½ as in Sect. 8.3.9, setp=0.001,Ξ”=10days, andsimulate for200days. Hint Thisdiscontinuousp(t) functioniseasiest implementedasaPythonfunction containing the indicatedif test. You may use the file SIRV1.py as starting point, butnote that it implementsa time-dependentp(t)viaanarray. Filename:SIRV_p_adapt.py. Exercise8.8:Make aSIRV Model with Time-LimitedEffectofVaccination We consider the SIRV model from Sect. 8.3.8, but now the effect of vaccination is time-limited. After a characteristic period of time,Ο€, the vaccination is no more effectiveand individualsare consequentlymovedfrom the V to the S categoryand can be infected again. Mathematically, this can be modeled as an average leakage βˆ’Ο€βˆ’1V from the V category to the S category (i.e., a gain Ο€βˆ’1V in the latter). Writeupthecompletemodel, implementit, andrerunthecasefromSect.8.3.8with variouschoicesofparameters to illustratevariouseffects. Filename:SIRV1_V2S.py. Exercise8.9:Refactora FlatProgram Consider the file osc_FE.py implementing the Forward Euler method for the oscillatingsystemmodel(8.43)–(8.44).Theosc_FE.pycodeiswhatweoftenrefer toasaflatprogram,meaningthat it is justonemainprogramwithnofunctions.Your task is to refactor the code in osc_FE.py according to the specifications below. Refactoring, means to alter the inner structure of the code, while, to a user, the programworks just asbefore. To easily reuse the numerical computations in other contexts, place the part that produces the numerical solution (allocation of arrays, initializing the arrays at time zero, and the time loop) in a function osc_FE(X_0, omega, dt, T), which returnsu, v, t. Place theparticular computationalexample inosc_FE.py in a function demo(). Construct the file osc_FE_func.py such that the osc_FE function can easily be reused in other programs. In Python, this means that osc_FE_func.py is a module that can be imported in other programs. The requirement of a module is that there should be no main program, except in the test block. You must therefore call demo from a test block (i.e., the block after if __name__ == ’__main__’). Filename:osc_FE_func.py. Exercise8.10:Simulate OscillationsbyaGeneralODESolver Solve the system (8.43)–(8.44) using the general solver ode_FE described in Sect. 8.3.6. Program the ODE system and the call to the ode_FE function in a separatefileosc_ode_FE.py. Equip this file with a test function that reads a file with correct u values and compares these with those computed by the ode_FE function. To find correct u
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
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
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python