Seite - 179 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 179 -
Text der Seite - 179 -
5.2 Exercises 179
TheOdespypackageoffers thismethodasodespy.Backward2Step.Thepurpose
of this exercise is tocompare threemethodsandanimate the threesolutions:
1. TheBackwardEulermethodwith t D0:001
2. Thebackward2-stepmethodwith t D0:001
3. Thebackward2-stepmethodwith t D0:01
Choose themodelproblemfromSect. 5.1.4.
Filename:rod_BE_vs_B2Step.py.
Exercise5.4:Exploreadaptiveand implicitmethods
Weconsider the sameproblemas inExercise5.2. Nowwewant to explore theuse
ofadaptiveand implicitmethods fromOdespy to see if theyaremoreefficient than
the Forward Euler method. Assume that youwant the accuracy provided by the
ForwardEulermethodwith itsmaximum t value. Since thereexists ananalytical
solution,youcancomputeanerrormeasure that summarizes theerror in spaceand
timeover thewhole simulation:
E D s
x t X
i X
n .Uni uni/2 :
Here,Uni is theexactsolution.UsetheOdespypackagetorunthefollowingimplicit
andadaptivesolvers:
1. BackwardEuler
2. Backward2Step
3. RKFehlberg
Experiment to see if you can use larger time steps than what is required by the
ForwardEulermethodandget solutionswith the sameorderofaccuracy.
Hint Toavoidoscillations in thesolutionswhenusingtheRKFehlbergmethod, the
rtol andatolparameters toRKFFehlbergmust be set no larger than 0.001 and
0.0001,respectively.Youcanprintoutsolver_RKF.t_alltoseeall thetimesteps
usedbytheRKFehlbergsolver(ifsolver is theRKFehlbergobject).Youcanthen
compare thenumberof timestepswithwhat is requiredby theothermethods.
Filename:ground_temp_adaptive.py.
Exercise5.5: Investigate the rule
a) The Crank-Nicolsonmethod for ODEs is very popular when combined with
diffusionequations. For a linearODEu0 Dau it reads
unC1 un
t D 1
2 .aunCaunC1/:
Apply the Crank-Nicolson method in time to the ODE system for a one-
dimensionaldiffusionequation. Identify the linear system tobesolved.
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