Seite - 131 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 131 -
Text der Seite - 131 -
4.3 OscillatingOne-DimensionalSystems 131
u = zeros(N_t+1)
v = zeros(N_t+1)
# Initial condition
u[0] = 2
v[0] = 0
# Step equations forward in time
for n in range(N_t):
v[n+1] = v[n] - dt*omega**2*u[n]
u[n+1] = u[n] + dt*v[n+1]
4.3.5 The2nd-OrderRunge-KuttaMethod(orHeun’sMethod)
A very popular method for solving scalar and vector ODEs of first order is the
2nd-orderRunge-Kuttamethod (RK2), also known asHeun’smethod. The idea,
first thinkingofascalarODE, is to formacentereddifferenceapproximationto the
derivativebetween two timepoints:
u0.tnC 1
2 t/ u nC1 un
t :
Thecentereddifferenceformula isvisualized inFig.4.20. Theerror in thecentered
difference is proportional to t2, oneorderhigher than the forwardandbackward
differences,whichmeans that ifwehalve t, theerror ismoreeffectively reduced
in thecentereddifferencesince it is reducedbya factorof four rather than two.
Theproblemwith such a centered scheme for thegeneralODEu0 D f.u;t/ is
thatweget
unC1 un
t Df.unC12 ;tnC12/;
which leads to difficulties sincewe do not knowwhatunC 1
2 is. However,we can
approximate the value off between two time levels by the arithmetic average of
Fig.4.20 Illustrationof acentereddifferenceapproximation to thederivative
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