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

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

Image of the Page - 60 -

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

Text of the Page - 60 -

60 3 Computing Integrals Bysimplifying the righthandsideof (3.15)weget bZ a f.x/dx h 2 Œf.x0/C2f.x1/C2f.x2/C : : :C2f.xn 1/Cf.xn/ (3.16) which ismorecompactlywrittenas bZ a f.x/dx h " 1 2 f.x0/C n 1X iD1 f.xi/C 1 2 f.xn/ # : (3.17) Composite integrationrules Theword composite is often usedwhen a numerical integrationmethod is ap- pliedwithmore thanonesub-interval. Strictly speaking then,writing, e.g., “the trapezoidalmethod”, should imply theuseofonlyasingle trapezoid,while “the composite trapezoidalmethod”is themostcorrectnamewhenseveral trapezoids areused.However, thisnamingconventionisnotalwaysfollowed,sosayingjust “thetrapezoidalmethod”maypointtoasingletrapezoidaswellasthecomposite rulewithmany trapezoids. 3.2.2 Implementation Specific orgeneral implementation? Supposeour primarygoalwas to compute the specific integral R1 0 v.t/dt with v.t/ D 3t2et3. First we played aroundwith a simple hand calculation to see what the methodwas about, before we (as one often does inmathematics) developed a general formula (3.17) for the general or “abstract” integral Rb a f.x/dx. To solve our specific problem R1 0 v.t/dt wemust thenapplythegeneral formula(3.17) to thegivendata (functionandintegral limits) in ourproblem. Although simple in principle, thepractical steps are confusing for manybecausethenotationintheabstractproblemin(3.17)differsfromthenotation in our special problem. Clearly, thef ,x, andh in (3.17) correspond to v, t, and perhaps t for the trapezoidwidth inour special problem. Theprogrammer’sdilemma 1. Shouldwewrite a special program for the special integral, using the ideas fromthegeneral rule (3.17),but replacingf byv,xby t, andhby t? 2. Should we implement the general method (3.17) as it stands in a general functiontrapezoid(f, a, b, n) and solve the specific problemat hand byaspecializedcall to this function? Alternative2 isalways thebest choice! The first alternative in the box above sounds less abstract and thereforemore attractive tomany. Nevertheless, as we hopewill be evident from the examples, the secondalternative is actually the simplestandmost reliable fromboth amath- ematical andprogrammingpointof view. Theseauthorswill claim that the second
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