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

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

Image of the Page - 89 -

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

Text of the Page - 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
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