Title: Numerical Methods notes by G. Houseman for EARS1160, ENVI2240, CCFD1160
1Numerical Methodsnotes by G. Housemanfor
EARS1160, ENVI2240, CCFD1160
- Lecture 3 Integration.
- Integration of discrete functions
- Interpretation of an integral
- Taylor's series (again!)
- Mid-point rule
- Trapezoid rule
- Romberg's method
- Simpson's rule
2Integration of Discrete Functions
- Given a function f(x), which could be represented
by the discrete function f(xi) at the set of
sample points xi, how do we evaluate the
definite integral ? - and the indefinite integral ?
- In the case of a definite integral, the answer is
a number and the main question is how to estimate
it accurately. - For the indefinite integral we are generating a
new discrete function, constructed from the
function f(x), but each entry of the new function
Fj F(xj) is just a definite integral, with
upper limit at point xj.
3Interpretation of an integral
- The definite integral
- is interpreted as the area between x a and x
b, between the lines y 0 and y f(x). - We can approximate the area by summing up the
areas of the set of thin vertical strips between
x xj and x xj1.
4Taylor's series (again!)
- The function f(x) in the range
- is approximated by the Taylor's series about the
midpoint xm of the range. - Then the integral is computed as the sum of the
separate integrals of the terms -
- Note that the second (and fourth, sixth, etc)
term is zero!
5Mid-point rule
- Then
-
- provides an estimate of (i) the integral (the
first term) and (ii) the error of the estimate
(the second term). The error is proportional to
(b-a)3 and to the curvature of the function at
the midpoint. - If we divide the interval into two segments,
there will be two error components, but each is
reduced in magnitude by a factor of 8 roughly, so
the total error decreases by a factor of 4. - If we divide the interval into N segments, the
discretisation error is reduced by the factor N2. - If we use too many segments however, the factor
(b-a) becomes very small and round-off error may
become large.
6Trapezoid Rule
- If we are using a discrete function, our function
is only defined at the points xj, j 1, N, so
using midpoints may be inconvenient. We can
simply estimate -
- in the mid-point rule, so that only the values at
the end points of the interval (or of the
sub-intervals) are needed. The error associated
with this approximation is obtained from the
Taylor's series at x a and x b, from which - and then
7Implementation of the Trapezoid rule
- The trapezoid rule is simply implemented as a
summation of all the segment areas. - If the N segment intervals of a discrete function
are of equal length Dx, there are 2 end points
and N-1 interior points some computational
efficiency is gained - Each interior point is added twice, at the right
end of one segment and at the left end of the
adjacent segment, so the factor of 1/2 cancels at
every summation point, except at the two end
points.
8Romberg's Method 1
- We saw that the error associated with the
trapezoid method for a single interval is - If we subdivide the interval into N segments, we
see that the error per segment decreases as N -3,
and therefore the total error decreases as N -2
(approximate because f"(x) is variable through
the interval, and often unknown). Assume that - where K depends on the curvature. Doubling the
number of mesh intervals causes the segment
length to be halved, so
9Romberg's Method 2
- We saw that the error associated with the
trapezoid method for a single interval is - From the estimate for N segments and that for 2N
segments - and thus we obtain an estimate for the value of
the integral that is significantly better than
the 2N estimate - but still only approximate because of arbitrary
variation of the second derivatives.
10Simpson's rule
- Accuracy of the trapezium method is limited by
loss of information about the curvature of the
function in between sample points. If we use
more points, in order to define the curvature,
more accuracy is possible. - If we use three regularly spaced points in the
discrete function, we can fit a parabola exactly
to those points, and the integral of this
best-fit parabola is then - In principle, this method is 4th order accurate,
i.e. the error on each segment integration
decreases as N -5. Since there are N segments,
the total error therefore decreases as N -4. - Exercise show that the above formula is obtained
if you fit a parabola to the 3 points at a, b,
and (ab)/2, and then integrate that parabola.
11Simpson's Rule
Another way of looking at this is that if we add
twice the midpoint rule to the trapezoid
rule we see that the leading terms in the error
cancel, and we are left with Simpson's
rule Exercise show that the magnitude of the
error term is as given here.
12Implementing Simpson's Rule
Since Simpson's rule requires 3 point estimates
for each segment, we take the interval segments
of a discrete function two at a time (requires an
even number N of segments) Odd numbered
points here contribute to the integral with a
weight of 4, compared to even points which
contribute with a weight of 2 (1 from each
neighbouring segment). This formula can give
accurate results for the definite integral if the
function is well behaved, but its application in
the computation of the indefinite integral is not
straightforward because of the requirement that
segments be taken 2 at a time.