Gaussian Quadrature
Gaussian Quadrature
G AUSSIAN QUADRATURE
−1
f ( x ) dx ≃ ∑ w k f ( x k ). (C.1)
k =1
The derivation of the positions xk of the sample points and the weights wk is
based on the mathematics of Legendre polynomials. The Legendre polyno-
mial PN ( x ) is an Nth-order polynomial in x that has the property
Z 1
x k PN ( x ) dx = 0 for all integer k in the range 0 ≤ k < N (C.2)
−1
and satisfies the normalization condition
Z 1 2 2
PN ( x ) dx = . (C.3)
−1 2N + 1
Thus, for instance, P0 ( x ) = constant, and the constant is fixed by (C.3) to give
P0 ( x ) = 1. Similarly, P1 ( x ) is a first-order polynomial ax + b satisfying
Z 1
( ax + b) dx = 0. (C.4)
−1
Carrying out the integral, we find that b = 0 and a is fixed by (C.3) to be 1,
giving P1 ( x ) = x. The next two polynomials are P2 ( x ) = 21 (3x2 − 1) and
P3 ( x ) = 12 (5x3 − 3x ), and you can find tables on-line or elsewhere that list
them to higher order.
Now suppose that q( x ) is a polynomial of degree less than N, so that it can
be written q( x ) = ∑kN=−01 ck x k for some set of coefficients ck . Then
Z 1 N −1 Z 1
q( x ) PN ( x ) dx = ∑ ck x k PN ( x ) dx = 0, (C.5)
−1 k =0 −1
514
A PPENDIX C | G AUSSIAN QUADRATURE
f ( x ) = q( x ) PN ( x ) + r ( x ), (C.6)
where we have used (C.5). This means that to find the integral of the poly-
nomial f ( x ) we have only to find the integral of the polynomial r ( x ), which
always has degree N − 1 or less.
But we already know how to solve this problem. As we saw in Section 5.6.1,
for any choice of sample points xk a polynomial of degree N − 1 or less can be
fitted exactly using the interpolating polynomials φk ( x ), Eq. (5.53), and then
the fit can be integrated to give a formula of the form
Z 1 Z 1 N
−1
f ( x ) dx =
−1
r ( x ) dx = ∑ w k r ( x k ), (C.8)
k =1
where Z 1
wk = φk ( x ) dx. (C.9)
−1
(See Eq. (5.60) on page 167.) Note that, unlike Eq. (C.1), the equality in Eq. (C.8)
is now an exact one (because the fit is exact).
Thus we have a method for integrating any polynomial of order 2N − 1 or
less exactly over the interval from −1 to 1: we divide by the Legendre polyno-
mial PN ( x ) and then integrate the remainder polynomial r ( x ) using any set of
N sample points we choose plus the corresponding weights.
This, however, is not a very satisfactory method. In particular the polyno-
mial division is rather complicated to perform. However, we can simplify the
procedure by noting that, so far, the positions of our sample points are uncon-
strained and we can pick them in any way we please. So consider again an
515
A PPENDIX C | G AUSSIAN QUADRATURE
integration rule of the form (C.1) and make the substitution (C.6), to get
N N N
∑ wk f (xk ) = ∑ wk q(xk ) PN (xk ) + ∑ wk r(xk ). (C.10)
k =1 k =1 k =1
But we know that PN ( x ) has N zeros between −1 and 1, so let us choose our N
sample points xk to be exactly the positions of these zeros. That is, let xk be the
kth root of the Legendre polynomial PN ( x ). In that case, PN ( xk ) = 0 for all k
and Eq. (C.10) becomes simply
N N
∑ w k f ( x k ) = ∑ w k r ( x k ). (C.11)
k =1 k =1
−1
f ( x ) dx = ∑ w k f ( x k ), (C.12)
k =1
516
A PPENDIX C | G AUSSIAN QUADRATURE
517
A PPENDIX C | G AUSSIAN QUADRATURE
where we have used (C.13) to eliminate the first term. This integral can now
be evaluated in the standard fashion
Z 1 2N +1
−1
r ( x ) dx = ∑ w k r ( x k ), (C.16)
k =1
where, as we have said, the sample points xk are the roots of the Legendre and
Stieltjes polynomials. Since r ( x ) is a polynomial of order N or less and there
are 2N + 1 sample points, Eq. (C.16) will always give an exact answer, to the
limits set by rounding error.
But now, using Eq. (C.14), we can also write
2N +1 2N +1 2N +1
∑ wk f ( x k ) = ∑ wk q( xk ) PN ( xk ) EN +1 ( xk ) + ∑ wk r ( x k )
k =1 k =1 k =1
2N +1
= ∑ w k r ( x k ), (C.17)
k =1
where the first sum has vanished because every sample point xk falls at a
zero of either PN ( x ) or EN +1 ( x ), so every term in the sum is zero. Combin-
ing Eqs. (C.15) to (C.17), we have
Z 1 2N +1
−1
f ( x ) dx = ∑ w k f ( x k ), (C.18)
k =1
518
A PPENDIX C | G AUSSIAN QUADRATURE
where the equality is an exact one. Thus this particular choice of sample points
does indeed give us an integration rule that is exact for all polynomial inte-
grands of order 3N + 1 or less.
The Gauss–Kronrod integration method now involves the following steps:
1. We evaluate the integral of f ( x ) first using standard Gaussian quadrature
on N points.
2. We evaluate it again using Gauss–Kronrod quadrature on 2N + 1 points.
N of those points are the same as those for Gaussian quadrature—the
roots of PN ( x )—so we do not have to recalculate f ( x ) at these points. We
can reuse the values from step 1. Only the values at the N + 1 new points
have to be calculated, and this can save us a lot of time.
3. The second estimate of the integral (since it is the more accurate of the
two) gives us our final result. And the difference between the two es-
timates gives us an estimate of the error, by analogy with Eq. (5.66). In
fact, the difference only gives us an upper bound on the error. The ac-
tual error is probably significantly smaller, but unfortunately no precise
expression for the error is known, so in practice one usually just uses the
difference, bearing in mind that the true error may in fact be smaller than
this.
519