Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Seite - 89 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 89 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 89 -

Bild der Seite - 89 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 89 -

3.8 Exercises 89 Exercise3.6:Exploreroundingerrorswith largenumbers The trapezoidal method integrates linear functions exactly, and this property was used in the test function test_trapezoidal_linear in the file test_ trapezoidal.py. Change the functionused inSect. 3.4.2 tof.x/ D 6 108x 4 106 and rerun the test.Whathappens?Howmustyouchange the test tomake it useful?Howdoes theconvergencerate testbehave?Anyneed foradjustment? Filename:test_trapezoidal2.py. Exercise3.7:Write test functions for R 4 0 p xdx Wewant to test how thetrapezoidal functionworks for the integral R4 0 p xdx. Two of the tests in test_trapezoidal.py are meaningful for this integral. Compute by hand the result of using 2 or 3 trapezoids and modify the test_ trapezoidal_one_exact_result function accordingly. Then modify test_ trapezoidal_conv_rate tohandle the square root integral. Filename:test_trapezoidal3.py. Remarks Theconvergence rate test fails. Printingoutr shows that the actual con- vergencerate for this integral is 1:5andnot 2. Thereason is that theerror in the trapezoidalmethod6 is .b a/3n 2f 00. / for some (unknown) 2 Œa;b . With f.x/ D px,f 00. /! 1 as ! 0, pointing to apotential problem in the size of the error. Runninga testwitha>0, say R4 0:1 p xdx shows that the convergence rate is indeed restored to 2. Exercise3.8:Rectanglemethods Themidpointmethod divides the interval of integration into equal-sized subinter- vals andapproximates the integral in each subinterval bya rectanglewhoseheight equals the functionvalueat themidpointof the subinterval. Instead,onemightuse either the left or right endof the subinterval as illustrated inFig. 3.4. This defines a rectangle method of integration. Theheight of the rectangle canbebasedon the left or right endor themidpoint. Fig.3.4 Illustrationof the rectanglemethodwithevaluating the rectangleheightbyeither the left or rightpoint 6http://en.wikipedia.org/wiki/Trapezoidal_rule#Error_analysis
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
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
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python