THE HANKEL MATRIX METHOD FOR GAUSSIANQUADRATURE IN 1 AND 2 DIMENSIONS
CARLOS SUERO, MAURICIO ALMANZAR
CONTENTS
1. Introduction 12. Proof of Gaussian Quadrature 63. Iterated 2-Dimensional Gaussian Quadrature 204. References 225. Experiments using Gaussian Quadrature Rule on [a, b] appendix-16. Experiments using Gaussian Quadrature Rulewith non-standard Measures appendix-27. Experiments comparing Gaussian Quadrature,the Trapezoid Rule, And Simpson’s Rule appendix-38. Experiments using Gaussian Quadrature RuleOn Disjoint Intervals appendix-49. Experiments using Iterated Gaussian QuadratureOver A Rectangle [a, b]× [c, d] appendix-5
1. Introduction
The Fundamental Theorem of Calculus allows one to compute the definite in-
tegral of a function over an interval [a, b] by using anti-derivatives. Once the anti-
derivative of the function is found, then it is evaluated at the end points of the interval.
For example, suppose we have a continuous function f(x) on [a, b]. If F (x) is an anti-
derivative of f(x), i.e. F ′(x) = f(x) for all x in [a, b], then∫ b
af(x)dx = F (b)− F (a).
0This project was carried out during the Spring, 2008 and Summer I, 2008 semesters with ProfessorLawrence A. Fialkow as the mentor. During Spring, 2008 the project was sponsored by SUNY/NSFAlliance for Minority Participation at SUNY New Paltz. The New Paltz AMP Director is ProfessorStacie Nunes from the Department of Physics. During Summer I, 2008 the project was sponsoredunder National Science Foundation Grant (number). The authors thank the sponsors for theirsupport.
1
For many functions f(x) we are not able to compute an anti-derivative in closed
form, so we can’t use the Fundamental Theorem of Calculus. For example f(x) = e−x2
does not have an anti-derivative in closed form. Instead, we will use numerical meth-
ods to estimate∫ b
af(x)dx. Gaussian Quadrature is one such method. The purpose
of our research is to find a way of estimating complicated definite integrals using the
Gaussian Quadrature rule. There are other numerical integration methods as well,
like Simpson’s rule and the Trapezoid rule. In some of the experiments, we will com-
pare the efficiency of Gaussian Quadrature to the efficiencies of Simpson’s Rule and
the Trapezoid Rule.
The idea behind Gaussian Quadrature is that given an integer M = 2n+1 > 0,
we can find points x1. . .xn in [a, b], and positive weights w1. . .wn, so that
(1.1)
∫ b
a
p(x)dx =
p∑i=1
wip(xi)
for every polynomial p(x) with deg p ≤ M . Then, for any continuous function f(x)
on the interval [a, b], we can approximate the integral∫ b
af(x)dx by the Gaussian
Quadrature rule Q(f) :=∑n
i=1 wif(xi), i.e,
(1.2)
∫ b
a
f(x)dx ≈ Q(f) =n∑
i=1
wif(xi).
To explain why this approach is effective, we have to consider the Weierstrass
Approximation Theorem (WAT). This theorem says that given a continuous function
2
f(x) on the interval [a, b] and a small ε > 0, we can find a polynomial p(x) so that
|f(x) − p(x)| < ε for all x in [a, b]. But we also have to take into account that to
get the best results from (1.1) and (1.2), the degree of the polynomial p(x) in WAT
must be less than the chosen M for the Gaussian Quadrature Rule. If deg p > M ,
the approximation in (1.2) may not be satisfactory.
Our definition of Gaussian Quadrature says that Q(f) =∑p
i=1 wif(xi). What
the Weierstrass Approximation Theorem suggests is that Q(f) ≈ ∫ b
af(x)dx. To see
this, consider the error,
(1.3) E := |Q(f)−∫ b
a
f(x)dx|.
For every polynomial p, we have
E = |Q(f)−Q(p) +Q(p)−∫ b
a
f(x)dx|
≤ |Q(f)−Q(p)|+ |Q(p)−∫ b
a
f(x)dx|.
Now suppose that deg p ≤ M . That means that
Q(p) =
∫ b
a
p(x)dx.
So,
(1.4) |Q(p)−∫ b
a
f(x)dx|
3
= |∫ b
a
p(x)dx−∫ b
a
f(x)dx|
= |∫ b
a
(p(x)− f(x))dx|
(1.5) ≤∫ b
a
|p(x)− f(x)|dx.
If |p(x)−f(x)| < ε throughout [a, b], then the expression in (1.5) is at most =∫ b
aεdx,
which is equal to ε(b− a). So we have
(1.6) |Q(p)−∫ b
a
f(x)dx| ≤ ε(b− a).
Now let’s consider |Q(f)−Q(p)|. This is equal to
|∑
wif(xi)−∑
wip(xi)|
= |∑
wi(f(xi)− p(xi))|
≤∑
wi|(f(xi)− p(xi)|
≤∑
wiε
= ε∑
wi
= ε(b− a) (since∑
wi = Q(1) =∫ b
a1dx = b− a).
So we have:
(1.7) |Q(f)−Q(p)| ≤ ε(b− a).4
Now we can show that the error (1.3) can be made small, as follows. Suppose we are
given an interval [a, b], a continuous function f(x) on [a, b], ε > 0, and let p(x) be
given by the Weierstrass Approximation Theorem, i.e. |p(x)− f(x)| < ε (a ≤ x ≤ b).
If we choose M ≥ deg p and apply the Gaussian Quadrature Rule using this M , then
from (1.7) and (1.4) we have
E = |Q(f)−∫ b
a
f(x)dx|
is
≤ |Q(f)−Q(p)|+ |Q(p)−∫ b
a
f(x)dx|.
≤ ε(b− a) + ε(b− a) = 2ε(b− a),
and since ε is small, E is also small.
Unfortunately, for small ε, deg p is often very large, so it is not practical to
use Gaussian Quadrature with M ≥ deg p. What the experiments will show is that
starting with M = 1, as M increases we can achieve 6 place accuracy in estimating
∫ b
af(x)dx by using fairly small values of M , though the smallest M that gives 6
place accuracy depends on several factors, such as the interval length b − a and the
complexity of f(x).
5
2. Proof of Gaussian Quadrature
We will derive an implementation of Gaussian Quadrature based on matrix
positivity and Lagrange interpolation, as described in [HK, page 115]. Recall the
following facts about integrals.
(2.1)
∫ b
a
(f(x) + g(x))dx =
∫ b
a
f(x)dx+
∫ b
a
g(x)dx.
(2.2)
∫ b
a
αf(x)dx = α
∫ b
a
f(x)dx.
The same rules apply to Gaussian Quadrature:
(2.3) Q(f(x) + g(x)) = Q(f(x)) +Q(g(x)).
(2.4) Q(αf(x)) = αQ(f(x)).
To prove (2.3), we have
Q(f(x) + g(x))
=
n∑i=0
wi(f(xi) + g(xi))
=
n∑i=0
(wif(xi) + wig(xi))
6
=
n∑i=0
wi(f(xi)) +
n∑i=0
wi(g(xi)) = Q(f(x)) +Q(g(x)).
The proof of (2.4) is similar.
Equations (2.1) - (2.4) show that it is enough to prove Gaussian Quadrature
for p(x) = xi (0 ≤ i ≤ M), i.e, we must find points and weights as in (1.1) such that
(2.5) βj :=
∫ b
a
xjdx = Q(xj) :=
n∑i=0
wixji , (0 ≤ j ≤ M).
Example 2.1. We will illustrate this reduction to monomials with p(x) = a0 + a1x.
Applying (2.1) and (2.2) we have,∫(ao+a1x)dx = a0
∫1dx+a1
∫xdx. If (2.5) holds,
then the last expression equals
a0Q(1) + a1Q(x),
and by (2.3)-(2.4), this equals
Q(a01 + a1x),
i.e, ∫(a0 + a1x)dx = Q(a0 + a1x). �
Example 2.2. Throughout this section we shall illustrate the method of Gaussian
Quadrature in detail for the case when m = 3, n = 1, and the interval is [0, 1]. We
need to find points x0, x1 in [0, 1] and positive weights w0, w1 such that:7
(2.6) β0 := 1 = w0x0 + w1x1
(2.7) β1 := 1/2 = w0x0 + w1x1
(2.8) β2 := 1/3 = w0x20 + w1x
21
(2.9) β3 := 1/4 = w0x30 + w1x
31
In the sequel we will show how to solve (2.6)-(2.9). �
To establish Gaussian Quadrature we need to look at the Hankel matrix H
defined as
H =
β0 β1 . . . βn
β1 β2 . . . βn+1
β2 β3 . . . βn+2
......
......
βn βn+1 . . . β2n
.
We will denote the columns of H by 1,t,. . . , tn. We also will consider the vector
v :=tn+1= (βn+1, . . . , β2n+1)t.
8
It is known that H is “positive” and invertible. That means 〈Ha, a〉 > 0
whenever a = 0. Another way to know that the matrix H is positive and invertible
is to show that the “nested” determinants of the “corners” are all positive. If Hi is
the i× i upper left hand corner of H , we must show that det Hi > 0 (1 ≤ i ≤ n+1).
Example 2.3. In our example, we have
H =
1 1/2
1/2 1/3
.
Then det(H1)= 1 and det(H2)= 1/3− 1/4 = 1/12 > 0. So H > 0. �
Since H is invertible, there is an unique vector a = (a0, . . . , an) such that
(2.10) Ha = v,
i.e,
a = H−1v,9
or equivalently,
a0β0 + . . .+ anβn = βn+1(2.11)
a0β1 + . . .+ anβn+1 = βn+2
......
...
a0βn + . . .+ anβ2n = β2n+1.
So tn+1 = a01+a1t+ . . .+ antn. Now let p(t) = tn+1 − (a01 + a1t+ . . .+ ant
n).
Example 2.4. In our example, we have
1 1/2
1/2 1/3
.
a0
a1
=
1/3
1/4
so
a0
a1
= H−1
1/3
1/4
= 12
1/3 −1/2
−1/2 1
1/3
1/4
and we find
a0 = −1/6, a1 = 1.10
So we have
p(t) = t2 − (−1/6 + t) = t2 − t+ 1/6. �
It is known that p(t) has exactly n+1 distinct real roots in [a, b] (see the proof
of Proposition 3.3 and Theorem 4.1 (iv) => (iii) in [CF]. Denote these roots by
x0 . . . xn.
Example 2.5. In our example, the roots of t2 − t+ 1/6 = 0 are
t = 1±√
1− 4(1)(1/6)/2 = 1±√
(5/3)/2,
so x0 ≈ 0.7886751346 and x1 ≈ 0.02113248654. Note that both x0 and x1 are in
[0, 1]. �
Now let’s look at the Vandermonde matrix V defined as
V =
x00 . . . x0
n
x10 . . . x1
n
......
...
xn0 . . . xn
n
.
It is known that because x0, . . . , xn are distinct, then V is invertible, i.e, det(V )
= 0 [HK, page 115].11
Example 2.6. In our example,
V =
1 1
x0 x1
.
So det(V ) = x1 − x0 = 0. �
Since V is invertible, there is an unique vector, ω := (ω0 . . . ωn), such that
(2.12) V ω =
β0
β1
...
βn
,
i.e,
(2.13)
1 . . . 1
x0 . . . xn
x02 . . . x2
n
......
...
xn0 . . . xn
n
ω0
...
ωn
=
β0
β1
...
βn
.
12
(2.13) is equivalent to the following system:
β0 = ω0 + . . .+ ωn (= Q(1))(2.14)
β1 = ω0x0 + . . .+ ωnxn (= Q(x))
......
...
βn = ω0xn0 + . . .+ ωnx
nn (= Q(xn)).
We claim that x0, . . . , xn and ω0, . . . , ωn solve the Gaussian Quadrature system
(2.5).
Example 2.7. In the example we have,
1 1
x0 x1
ω0
ω1
=
β0
β1
,
or equivalently
w0 + w1 = β0,
and
w0x0 + w1x1 = β1,
where w0 ≈ 0.623893 and w1 ≈ 0.376107. �
The Gaussian Quadrature system (2.5) is equivalent to the system of equations
in (2.14) together with the following system:13
βn+1 = ω0xn+10 + . . .+ ωnx
n+1n (= Q(xn+1))(2.15)
βn+2 = ω0xn+20 + . . .+ ωnx
n+2n (= Q(xn+2))
... =...
β2n+1 = ω0x2n+10 + . . .+ ωnx
2n+1n (= Q(x2n+1)).
Since (2.14) is satisfied from (2.13), we are going to focus on (2.15). Consider
the first equation of (2.15),
βn+1 = ω0xn+10 + . . .+ ωnx
n+1n .
We have
βn+1 =
∫ b
a
xn+1dx
and
Q(xn+1) ≡n∑
i=0
wixn+1i .
Since each xi is a root of tn+1 = a0 + a1t+ . . .+ antn, we have
Q(xn+1) =n∑
i=0
wixn+1i
14
=n∑
i=0
wi(a01 + a1xi + . . .+ anxni )
= a0
∑wi + a1
∑wixi + . . .+ an
∑wix
ni
= a0β0 + a1β1 + . . .+ anβn (by (2.14)).
By the first equation of (2.11), the last expression is equal to βn+1, so we
conclude that
(2.16) Q(xn+1) = βn+1.
For the second equation of (2.15), we have
Q(xn+2) ≡∑
wixn+2i .
Since each xi is a root of tn+1 = a0 + a1t + . . . + antn, xi is also a root of tn+2 =
a0t+ . . .+ antn+1. So we have
Q(xn+2) =∑
wixn+2i
=∑
wi(a0xi + . . .+ anxn+1i )
15
= a0
∑wixi + . . .+ an
∑wix
n+1i
= a0β1 + . . .+ anβn+1 (by (2.14) and (2.16)).
By the second equation of (2.11) the last expression is equal to βn+2, so we
conclude that
(2.17) Q(xn+2) = βn+2.
Following the same procedure, we are able to prove the rest of the equations in
the set (2.15). This completes the proof that the points xi, . . . , xn and the weights
wi, . . . , wn satisfy the Gaussian Quadrature system (1.1).
From the above discussion, we have distinct points x0, . . . , xn in [a, b] and
weights w0, . . . , wn such that
(2.18) Q(p) :=
n∑i=0
wip(xi) =
∫ b
a
p(x)dx (deg p ≤ 2n+ 1).
To complete the proof of Gaussian Quadrature as in (1.1) we must still show that
each wi > 0. In what follows we will use Lagrange polynomials to prove that each
wi > 0. Lagrange Interpolation says that given distinct points x0, . . . , xn and given
numbers y0, . . . , yn there is a unique polynomial p(x) with deg p = n, such that
p(xi) = yi (0 ≤ i ≤ n).
16
Example 2.8. Consider Lagrange Interpolation with n=1. The Lagrange polynomial
of degree 1 such that p(x0) = y0 and p(x1) = y1 is
(2.19) p1(x) :=y0(x− x1)
(x0 − x1)+
y1(x− x0)
(x1 − x0).
The curve y = p(x) is the line connecting (x0, y0) and (x1, y1). �
The Lagrange polynomial p1(x) in (2.19) is the basis for the Trapezoidal Rule.
In this rule, we subdivide [a, b] into n equal subintervals [xi, xi+1] (0 ≤ i ≤ n +
1, x0 = a, xn = b). On interval [xi, xi+1], we approximate f(x) by the line connecting
(xi, f(xi)) to (xi+1, f(xi+1)); this line is the graph of the Lagrange polynomial p1(x)
such that
p1(xi) = yi := f(xi)
and
p1(xi+1) = yi+1 := f(xi+1).
We then approximate∫ xi+1
xif(x)dx by the area of the trapezoid determined by the
graph of p1 between xi and xi+1:
∫ xi+1
xi
f(x)dx ≈ 1
2(xi+1 − xi)(f(xi) + f(xi+1)).
Letting h = xi+1 − xi (0 ≤ i ≤ n− 1), we may express the Trapezoidal Rule by17
(2.20)
∫ b
a
f(x)dx = h
n−1∑i=1
f(a+ ih) + h(f(a) + f(b)
2).
Example 2.9. For n = 2, we have distinct points x0, x1, x2, and values y0, y1, y2. The
Lagrange polynomial p(x) looks like the following:
(2.21) p2(x) :=y0(x− x1)(x− x2)
(x0 − x1)(x0 − x2)+
y1(x− x0)(x− x2)
(x1 − x0)(x1 − x2)+
y2(x− x0)(x− x1)
(x2 − x0)(x2 − x1).
The curve y = p2(x) is the unique parabola passing through (x0, y0), (x1, y1), (x2, y2). �
The Lagrange polynomial p2(x) in (2.21) is the basis for Simpson’s Rule. In this
rule, we approximate y = f(x) by a piecewise-parabolic curve y = g(x) on [a, b], using
p2(x) for each piece of g(x). We can then approximate∫ b
af(x)dx by
∫ b
ag(x)dx. If we
let the function f be tabulated at points x0, x1 and x2, equally spaced by distance h,
and we let yi = fi := f(xi) (0 ≤ i ≤ 2), then Simpson’s rule says that
∫ x2
x0
f(x)dx =
∫ x0+2h
x0
f(x)dx
≈∫ x0+2h
x0
p2(x)dx =1
3h(f0 + 4f1 + f2).
18
If we use n double-intervals with equally spaced points x0, x1, . . . , x2n, then by using
the above method on each double-interval and adding up, we get
(2.22)
∫ b
a
f(x)dx ≈ h
3(n−1∑i=0
(2f(a+ 2ih) + 4f(a+ (2i+ 1)h)) + f(b)− f(a)).
The general formula for the Lagrange polynomial p(x) such that p(xi) = yi (p ≤ i ≤ n)
is clear from (2.19) and (2.21). If q(x) is another polynomial of deg n such that
q(xi) = yi (0 ≤ i ≤ n), then (p− q)(xi) = 0. Since deg p− q ≤ n and p− q has n+ 1
distinct roots, it follows that p − q = 0, i.e. p = q. So there is a unique Lagrange
polynomial of deg n.
Now we return to Gaussian Quadrature, and the claim that ωi > 0 (0 ≤ i ≤ n).
We fix j and we let p(x) ≡ pj(x) be the Lagrange polynomial of degree n such that
p(xi) = 0 for i = j and p(xj) = 1. Now consider q(x) = p(x)2. Since deg q = 2n (<
2n+ 1), then from (2.18),
(2.23)
∫ b
a
q(x)dx =
n∑i=0
wiq(xi).
Note that q(x) ≥ 0 and q(xj) = 1, so
∫ b
a
q(x)dx > 0.
19
Therefore,
0 <
∫ b
a
q(x)dx =n∑
i=0
wiq(xi) = wj ,
so we conclude that wj > 0 (0 ≤ j ≤ n). This completes the proof of the Gaussian
Quadrature rule (1.1).
3. Iterated 2-Dimensional Gaussian Quadrature
In 1-dimensional Gaussian Quadrature we showed that given n > 0 and an
interval [a, b], there exist points x0, . . . , xn in [a,b] and positive weights ω0, . . . , ωn,
such that∫ b
ap(x)dx =
∑ni=0 wip(xi) (deg p ≤ 2n+ 1).
Now we are going to use 1-dimensional Gaussian Quadrature to find a rule that
works in two dimensions. We are given a rectangle in the plane, R = [a, b] × [c, d],
and a continuous function f(x, y) on R. We want to approximate∫ ∫
Rf(x, y)dxdy.
Given n, let x0, . . . , xn, ω0, . . . , ωn be the Gaussian Quadrature points and weights
for [a, b], so (1.1) holds. Let y0, . . . , yn, s0, . . . , sn be the Gaussian Quadrature points
and weights for [c, d], so that
∫ d
c
q(y)dy =n∑
j=0
sjq(yj) (deg q ≤ 2n+ 1).
Now for a function f(x, y), defined on rectangle R, let
Q(f) :=
n∑i=0
n∑j=0
sjwif(xi, yj).
20
For a polynomial p(x, y), let py(x) = p(x, y)(a polynomial in x with y fixed), and let
px(y) = p(x, y)(a polynomial in y with x fixed).
We are claming that if p(x, y) is a polynomial, with deg py(x) ≤ 2n + 1 and
deg px(y) ≤ 2n + 1, then
Q(p) =
∫ d
c
∫ b
a
p(x, y)dxdy(≡∫ ∫
R
p(x, y)dxdy).
If we fix x and consider
g(y) := px(y) = p(x, y),
then
deg g ≤ 2n + 1,
so ∫ d
c
g(y)dy =n∑
j=0
sjg(yj),
which is the same as
H(x) :=
∫ d
c
p(x, y)dy =n∑
j=0
sjp(x, yj) (a ≤ x ≤ b).
So we have ∫ b
a
∫ d
c
p(x, y)dydx =
∫ b
a
∫ d
c
px(y)dydx =
∫ b
a
H(x)dx
=
∫ b
a
(
n∑j=0
sjp(x, yj))dx
=
n∑j=0
sj
∫ b
a
p(x, yj)dx (deg p(x, yj) ≤ 2n+ 1)
21
=
n∑j=0
sj
n∑i=0
wip(xi, yj) =
n∑j=0
n∑i=0
sjwip(xi, yj)
= Q(p(x, y)).
So Q(p) =∫ ∫
Rp(x, y)dxdy whenever deg px(y) ≤ 2n + 1 and deg py(x) ≤
2n + 1. For a general function f(x, y), that is defined and continuous on R, we
may approximate∫ ∫
Rf(x, y)dxdy by Q(f). In appendix-5 we will illustrate this
approximation with numerical examples.
References
[CF] R.E. Curto, L.A. Fialkow,”Recursiveness, positivity, and truncated moment problems”,Houston Journal of Mathematics 17(1991), 603-635.
[HK] Hoffman, R.Kunze, Linear Algebra, Prentice-Hill, 1961.
Department of Computer Science, State University of New York, New Paltz,
NY 12561, USA
22