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

Page - 158 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - 158 -

Image of the Page - 158 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - 158 -

158 6 ComputingIntegralsandTestingCode howcanwe approximate this integralbynumericalmethods? Derivation via One-Dimensional Integrals Since we know how to deal with integrals in one variable, a fruitful approach is to view the double integral as two integrals,each inonevariable,whichcanbeapproximatednumericallybyprevious one-dimensionalformulas.To thisend,we introduceahelpfunctiong(x)andwrite ∫ b a ∫ d c f(x,y)dydx= ∫ b a g(x)dx, g(x)= ∫ d c f(x,y)dy. Eachof the integrals ∫ b a g(x)dx, g(x)= ∫ d c f(x,y)dy can be discretized by any numerical integration rule for an integral in one variable. Let us use the midpoint method (6.20) and start with g(x) = ∫d c f(x,y)dy. We introduceny intervals on [c,d]with lengthhy. The midpoint rule for this integral thenbecomes g(x)= ∫ d c f(x,y)dy≈hy ny−1∑ j=0 f(x,yj), yj = c+ 1 2 hy+jhy . The expression looks somewhat different from (6.20), but that is because of the notation:sinceweintegrate in theydirectionandwillhavetoworkwithbothx and y ascoordinates,wemustuseny forn,hy forh, and thecounter i ismorenaturally called j when integrating iny. Integrals in thex direction will usehx andnx forh andn, and i ascounter. The double integral is ∫b a g(x)dx, which can be approximated by the midpoint method: ∫ b a g(x)dx≈hx nx−1∑ i=0 g(xi), xi =a+ 1 2 hx+ ihx . Putting the formulas together, we arrive at the composite midpoint method for a double integral: ∫ b a ∫ d c f(x,y)dydx≈hx nx−1∑ i=0 hy ny−1∑ j=0 f(xi,yj) =hxhy nx−1∑ i=0 ny−1∑ j=0 f(a+ hx 2 + ihx,c+ hy 2 +jhy). (6.29)
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
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