Page - 65 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python
Image of the Page - 65 -
Text of the Page - 65 -
3.3 TheCompositeMidpointMethod 65
Thepresent integralproblemsresult inshortcode. Inmorechallengingengineer-
ingproblems the codequicklygrows tohundredsand thousandsof lines. Without
abstractions in termsofgeneral algorithms ingeneral reusable functions, the com-
plexityof theprogramgrowsso fast that itwill beextremelydifficult tomakesure
that theprogramworksproperly.
Another advantage of packagingmathematical algorithms in functions is that
a functioncanbe reusedbyanyone to solve aproblemby just calling the function
with a proper set of arguments. Understanding the functionβs inner details is not
necessary to compute a new integral. Similarly, youcanfind libraries of functions
on the Internet and use these functions to solve your problems without specific
knowledgeofeverymathematicaldetail in the functions.
This desirable feature has its downside, of course: the user of a functionmay
misuse it, and the functionmaycontainprogrammingerrorsand lead towrongan-
swers. Testing theoutputofdownloadedfunctions is thereforeextremely important
before relyingon the results.
3.3 TheCompositeMidpointMethod
The idea Rather thanapproximating theareaundera curveby trapezoids,wecan
use plain rectangles (Fig. 3.3). Itmay sound less accurate to use horizontal lines
andnotskewlinesfollowingthefunctiontobeintegrated,butanintegrationmethod
basedonrectangles (themidpointmethod) is in fact slightlymoreaccurate than the
onebasedon trapezoids!
Fig.3.3 Computing approximately the integral of a function as the sumof the areas of the rect-
angles
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