Page - 132 - in Programming for Computations β Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Image of the Page - 132 -
Text of the Page - 132 -
132 6 ComputingIntegralsandTestingCode
Calculatingan integral is traditionallydoneby
β« b
a f(x)dx=F(b)βF(a), (6.1)
where
f(x)= dF
dx .
The major problem with this procedure is that we need to find an anti-derivative
F(x) corresponding to a givenf(x). For some relatively simple integrandsf(x),
findingF(x) isadoabletask.Often,however,it isreallychallenging,andsometimes
even impossible!
Themethod(6.1)providesanexactoranalyticalvalueof theintegral. Ifwerelax
the requirement of computing an exact value for the integral, and instead look for
approximate values, produced by numerical methods, integration becomes a very
straightforward task for almost any given f(x)! In particular, we do not need an
anti-derivativeF(x) at all, since it is just the known integrandf(x) that enters the
calculations.
The (apparent) downside of a numerical method is that it can only find an
approximate answer. Leaving the exact for the approximate is a mental barrier in
the beginning, but remember that most real applications of integration will involve
anf(x) function that containsphysicalparameters,whichare measuredwith some
error. That is, f(x) is very seldom exact, and it does not make sense trying to
compute the integralwitha smaller error than theonealreadypresent inf(x).
Another advantage of numerical methods is that we can easily integrate a
functionf(x) that is only known as samples, i.e., discrete valuesat somex points,
and not as a continuous function ofx expressed through a formula. This is highly
relevantwhenf is measured inaphysical experiment.
6.1 BasicIdeasofNumerical Integration
We consider the integral
β« b
a f(x)dx. (6.2)
Most numerical methods for computing this integral split up the original integral
into a sum of several integrals, each covering a smaller part of the original
integration interval [a,b]. This re-writing of the integral is based on a selection
of integration points xi, i = 0,1,.. .,n that are distributed on the interval [a,b].
Integration points may, or may not, be evenly distributed. An even distribution
simplifies expressions and is often sufficient, so we will mostly restrict ourselves
to thatchoice.The integrationpointsare thencomputedas
xi =a+ ih, i=0,1,.. .,n, (6.3)
Programming for Computations β Python
A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
- Title
- Programming for Computations β Python
- Subtitle
- A Gentle Introduction to Numerical Simulations with Python 3.6
- Volume
- Second Edition
- Authors
- Svein Linge
- Hans Petter Langtangen
- Publisher
- Springer Open
- Date
- 2020
- Language
- English
- License
- CC BY 4.0
- ISBN
- 978-3-319-32428-9
- Size
- 17.8 x 25.4 cm
- Pages
- 356
- Keywords
- Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
- Category
- Informatik