Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Seite - 159 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 159 -

Bild der Seite - 159 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 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:
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
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
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python