Seite - 166 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 166 -
Text der Seite - 166 -
166 5 SolvingPartialDifferentialEquations
The initial conditionsare
u0.0/D s.0/; (5.12)
ui.0/DI.xi/; i D1;:: :;N : (5.13)
Wecanapplyanymethodfor systemsofODEs tosolve (5.9)–(5.11).
5.1.2 ConstructionofaTestProblemwithKnownDiscreteSolution
At this point, it is tempting to implement a real physical case and run it. However,
partial differential equations constitute a non-trivial topicwheremathematical and
programmingmistakes comeeasy. Abetter start is therefore to address a carefully
designedtest examplewherewecancheck that themethodworks. Themostattrac-
tive examples for testing implementations are thosewithout approximationerrors,
becauseweknowexactlywhat numbers the programshould produce. It turns out
that solutionsu.x;t/ that are linear in timeand in spacecanbeexactly reproduced
bymost numericalmethods for partial differential equations. Acandidate solution
mightbe
u.x;t/D .3tC2/.x L/:
Inserting thisu in thegoverningequationgives
3.x L/D0Cg.x;t/ ) g.x;t/D3.x L/:
Whatabout theboundaryconditions?Werealize that@u=@xD 3tC2 forx DL,
which breaks the assumption of @u=@x D 0 at x D L in the formulation of the
numericalmethodabove.Moreover,u.0;t/D L.3tC2/, sowemust set s.t/D
L.3tC2/ands0.t/D 3L. Finally, theinitialconditiondictatesI.x/D2.x L/,
but recall that we must have u0 D s.0/, and ui D I.xi/, i D 1;:: :;N: it is
important thatu0 starts out at the right value dictated by s.t/ in case I.0/ is not
equal thisvalue.
Firstweneedtogeneralizeourmethodtohandle@u=@xD ¤0atxDL.We
thenhave
uNC1.t/ uN 1.t/
2 x D ) uNC1 DuN 1C2 x;
which inserted in (5.7)gives
duN.t/
dt Dˇ2uN 1.t/C2 x 2uN.t/
x2 CgN.t/: (5.14)
5.1.3 Implementation:ForwardEulerMethod
In particular, we may use the Forward Euler method as implemented in the
general function ode_FE in the module ode_system_FE from Sect. 4.2.6. The
ode_FE function needs a specification of the right-hand side of theODE system.
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