Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 165 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 165 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 165 -

Image of the Page - 165 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 165 -

5.1 FiniteDifferenceMethods 165 Weremark that a separateODE for the (known)boundaryconditionu0 D s.t/ is not strictly needed.Wecan justworkwith theODEsystem foru1;:: :;uN, and in theODEforu0, replaceu0.t/by s.t/. However, these authorsprefer tohavean ODEforeverypointvalueui, i D0;:: :;N ,whichrequiresformulatingtheknown boundaryatxD0asanODE.Thereason for including theboundaryvalues in the ODE system is that the solution of the system is then the complete solution at all meshpoints,which is convenient, since special treatmentof theboundaryvalues is thenavoided. The condition @u=@x D 0 at x D L is a bit more complicated, but we can approximate thespatial derivativebyacenteredfinitedifference: @u @x Λ‡ Λ‡ Λ‡ Λ‡ iDN uNC1 uN 1 2 x D0: ThisapproximationinvolvesafictitiouspointxNC1outside thedomain.Acommon trick is to use (5.7) for i DN andeliminateuNC1byuseof thediscreteboundary condition (uNC1 DuN 1): duN.t/ dt DΛ‡2uN 1.t/ 2uN.t/ x2 CgN.t/: (5.8) That is,wehaveaspecial versionof (5.7)at theboundary i DN . Whataboutsimplerfinitedifferencesattheboundary? Somereadermay think that a smarter trick is to approximate theboundarycon- dition@u=@x atxDLbyaone-sideddifference: @u @x Λ‡ Λ‡ Λ‡ Λ‡ iDN uN uN 1 x D0: This gives a simple equationuN D uN 1 for the boundaryvalue, and a corre- spondingODEu0N Du0N 1. However, this approximationhas anerror of order x,while thecenteredapproximationweusedabovehasanerroroforder x2. The finite difference approximationwe used for the second-order derivative in the diffusion equation also has an error of order x2. Thus, ifweuse the sim- pler one-sideddifferenceabove, it turnsout thatwe reduce theoverall accuracy of themethod. We are now in a position to summarize howwe can approximate the partial differential equationproblem(5.1)–(5.4)byasystemofordinarydifferential equa- tions: du0 dt D s0.t/; (5.9) dui dt D Λ‡ x2 .uiC1.t/ 2ui.t/Cui 1.t//Cgi.t/; i D1;:: :;N 1; (5.10) duN dt D 2Λ‡ x2 .uN 1.t/ uN.t//CgN.t/: (5.11)
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python