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

Page - 159 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 159 -

Image of the Page - 159 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 159 -

4.4 Exercises 159 a) Solve the systemforun andvn. b) Implement the found formulas forun and vn in a program for computing the entirenumerical solutionof (4.43)–(4.44). c) Run the programwith a t corresponding to 20 time steps per period of the oscillations (seeSect. 4.3.3 for how tofind such a t). What doyouobserve? Increase to 2000 time steps per period. Howmuchdoes this improve the solu- tion? Filename:osc_BE.py. Remarks While the Forward Eulermethod applied to oscillation problemsu00 C !2u D 0 gives growing amplitudes, theBackwardEulermethod leads to signifi- cantlydampedamplitudes. Exercise4.15:UseHeun’smethodfor theSIRmodel Makeaprogramthatcomputes thesolutionof theSIRmodel fromSect. 4.2.1both bytheForwardEulermethodandbyHeun’smethod(orequivalently: the2nd-order Runge-Kuttamethod)fromSect.4.3.5.Comparethe twomethodsin thesimulation case from Sect. 4.2.3. Make two comparison plots, one for a large and one for asmall timestep. Experiment tofindwhat“large”and“small” shouldbe: the large onegives significantdifferences,while the smallone lead toverysimilar curves. Filename:SIR_Heun.py. Exercise4.16:UseOdespy tosolveasimpleODE Solve u0 D auCb; u.0/DU0; t 2 .0;T by theOdespy software. Let the problemparametersa andb be arguments to the right-hand side function that specifies theODE to be solved. Plot the solution for thecasewhenaD2,bD1,T D6=a, andweuse100 time intervals in Œ0;T . Filename:odespy_demo.py. Exercise4.17: SetupaBackwardEuler schemeforoscillations Write theODEu00 C!2u D 0 as a systemof twofirst-orderODEsanddiscretize thesewithbackwarddifferencesas illustrated inFig.4.19. Theresultingmethod is referred to as aBackwardEuler scheme. Identify thematrixand right-handsideof the linearsystemthathas tobesolvedateachtimelevel. Implement themethod,ei- therfromscratchyourselforusingOdespy(thenameisodespy.BackwardEuler). Demonstrate that contrary toaForwardEuler scheme, theBackwardEuler scheme leads to significant non-physical damping. Thefigure belowshows that evenwith 60 timestepsperperiod, the results after a fewperiodsareuseless:
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
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python