Seite - 60 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Bild der Seite - 60 -
Text der Seite - 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
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