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

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

Image of the Page - 78 -

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

Text of the Page - 78 -

78 3 Computing Integrals In [6]: %timeit midpoint_vec(v, 0, 1, 1000000) 1 loops, best of 3: 379 ms per loop In [7]: %timeit midpoint(v, 0, 1, 1000000) 1 loops, best of 3: 8.17 s per loop In [8]: 8.17/(379*0.001) # efficiency factor Out[8]: 21.556728232189972 Wesee that the vectorized version is about 20 times faster: 379ms versus 8.17s. Theresults for the trapezoidalmethodareverysimilar, and thefactorofabout20 is independentof thenumberof intervals. 3.7 DoubleandTripleIntegrals 3.7.1 TheMidpointRuleforaDoubleIntegral Givenadouble integralovera rectangulardomain Ε’a;b Ε’c;d , bZ a dZ c f.x;y/dydx; howcanweapproximate this integralbynumericalmethods? Derivation via one-dimensional integrals Sincewe know how to deal with in- tegrals in one variable, a fruitful approach is to view the double integral as two integrals, eachinonevariable,whichcanbeapproximatednumericallybyprevious one-dimensionalformulas. Tothisend,weintroduceahelpfunctiong.x/andwrite bZ a dZ c f.x;y/dydx D bZ a g.x/dx; g.x/D dZ c f.x;y/dy : Eachof the integrals bZ a g.x/dx; g.x/D dZ c f.x;y/dy canbediscretizedbyanynumerical integration rule foran integral inonevariable. Let us use themidpointmethod (3.21) and start withg.x/ D Rd c f.x;y/dy. We introduceny intervals on Ε’c;d with lengthhy. Themidpoint rule for this integral thenbecomes g.x/D dZ c f.x;y/dy hy ny 1X jD0 f.x;yj/; yj D cC 1 2 hy Cjhy :
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