Seite - 173 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 173 -
Text der Seite - 173 -
5.1 FiniteDifferenceMethods 173
Fig.5.3 Snapshots of thedimensionless solutionofa scaledproblem
rhs[1:N-1] = (beta/dx**2)*(u[2:N+1] - 2*u[1:N] + u[0:N-1]) +
g(x[1:N], t)
This rewrite speedsup thecodebyabout a factor of 10. Acomplete code is found
in thefilerod_FE_vec.py.
5.1.6 UsingOdespytoSolvetheSystemofODEs
LetusnowshowhowtoapplyageneralODEpackagelikeOdespy(seeSect.4.3.6)
to solveourdiffusionproblem.As longaswehavedefineda right-handside func-
tionrhs this isverystraightforward:
import odespy
solver = odespy.RKFehlberg(rhs)
solver.set_initial_condition(U_0)
T = 1.2
N_t = int(round(T/float(dt)))
time_points = linspace(0, T, N_t+1)
u, t = solver.solve(time_points)
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