Seite - 282 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Bild der Seite - 282 -
Text der Seite - 282 -
282 8 SolvingOrdinaryDifferentialEquations
Exercise8.18:The Three-StepAdams-BashforthMethod
ThisexercisebuildsonExercise8.17,soyoubetterdothatonefirst.Anothermulti-
stepmethod,is the three-stepAdams-Bashforthmethod.This isa thirdordermethod
witha computationalscheme that reads:
un+1 =un+Δt
12 (
23f(un,tn)−16f(un−1,tn−1)+5f(un−2,tn−2) )
.
forn=2,3,.. .,Nt −1,withu0 =U0.
a) Assumethat someoneimplemented theschemeas follows:
def adams_bashforth_3(f, U_0, dt, T):
"""Third-order Adams-Bashforth scheme for solving first order ODE"""
N_t = int(round(T/dt))
u = np.zeros(N_t+1)
t = np.linspace(0, N_t*dt, len(u))
u[0] = U_0
# Compute missing starting values
u[1] = 100*np.exp(0.1*dt)
u[2] = 100*np.exp(0.1*(2*dt))
for n in range(1, N_t, 1):
u[n+1] = u[n] + (dt/12)*(23*f(u[n], t[n]) - \
16*f(u[n-1], t[n-1]) +\
5*f(u[n-2], t[n-2]))
return u, t
There is one (known!)bug here,find it! Try first by simply reading the code. If not
successful,youmaytry to run it anddosometesting onyourcomputer.
Also, what would you say about the way that missing starting values are
computed?
b) RepeatExercise8.17,using thegiven three-stepmethod in steadof the two-step
method.
Note that with the three-step method, you need 3 starting values. Use the
Runge-Kutta third order scheme for this purpose. However, check also the
convergencerate of theschemewhenmissingstartingvaluesarecomputedwith
ForwardEuler in stead.
Filename:Adams_Bashforth_3.py.
Exercise8.19:Use aBackwardEuler SchemeforOscillations
Consider(8.43)–(8.44)modelinganoscillatingengineeringsystem.This2×2ODE
systemcanbesolvedbytheBackwardEulerscheme,which isbasedondiscretizing
derivatives by collecting information backward in time. More specifically,u′(t) is
approximatedas
u′(t)≈ u(t)−u(t−Δt)
Δt .
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