In the method of Newton-Cotes quadrature based on equally
spaced node points, we are free to choose the weights
as variables to achieve the highest degree of accuracy of
if it is odd, or if is even. In comparison, in the method
of Gauss-Legendre quadrature considered below, we are free to choose
the node points, as well as the weights. As number of
free variables in the method is doubled, its degree of accuracy is
also doubled to reach .
Reconsider the quadrature rule based on the Lagrange interpolation
of the integrand :
|
(155) |
where
are the weights independent of the
integrand :
|
(156) |
To derive the algorithm, we first make the following assumptions:
- The integrand is a polynomial of degree no higher
than ,
- The integral limits are and ,
- The node points
, called Gauss points,
are the roots of an (n+1)th polynomial
in
an orthogonal polynomial family, here assumed to be the
Legendre polynomial,
i.e.,
.
Dividing by
, we get
i.e., |
(157) |
where the quotient is a polynomial of degree
,
and the remainder is a polynomial of degree no higher than
. Evaluating at any Gauss point , we have
|
(158) |
Also, as is a polynomial of degree no higher than , it
can be expressed as a linear combination of the Legendre polynomials
of degree no higher than , its inner product with
is
zero due to the orthogonality of the Legendre polynomials:
|
(159) |
Now the integral can be carried out by
We see that under the assumptions above, the integral can be
calculated exactly as a linear combination of , the
integrand evaluated at the Gauss node points
,
the roots of the Legendre polynomial
.
While the weights
of the Gauss-Legendre
quadrature can be found by Eq. (?) by integrating the Lagrange
basis polynomials , they can also be found more
conveniently by the method of undetermined coefficients.
Specifically, byassuming the integrand to be polynomials of
different orders
, we get the
following equations:
|
(160) |
Or, alternatively, by assuming
,
we get
|
(161) |
Solving either of these systems of equations we get the
weights
.
We can also assume the integrand to be a special function
with to be one of the
roots of
, i.e.,
. The integral of this
function can be found by the Gauss-Legendre quadrature rule:
As
are the roots of
, all terms
in the summation are zero except the ith one, an indeterminate
form which can be evaluated by L'Hopital's rule:
|
(162) |
Now the equation above becomes
|
(163) |
On the other hand, the integral can be carried out using
integration by parts with
and
, we get
,
and
Here the integral of the second term on the right-hand side is an
inner product of , a polynomial of degree lower than ,
and
, which is zero due to the orthogonality of the
Legendre polynomials, and we have also used the fact that
. Equating the two expressions for the integral,
we get
|
(164) |
Finally we show that the integral limits can be
generalized to by the following linear mapping:
|
(165) |
with
. Now we get the Gauss-Legendre quadrature
rule:
which is exact if the integrand is a polynomial of degree no higher
than , twice as high as the the degree of accuracy of the
Newton-Cotes quadrature based on equally spaced node points.
Example: When , the Gauss nodes are the roots of
:
, and the weights can be found Eq. (?):
Alternatively and more conveniently, we can also obtain these
weights by Eq. (??). We first find
|
(166) |
and then evaluate it at the Gauss nodes to get
, and
. Now we can get the
weights:
There weights can also be obtained by solving either of the following
equivalent equation systems:
|
(167) |
and
|
(168) |
where
.
Now consider integrating a simple polynomial from
to . First, to linearly map the integral limits to ,
we find
and get
|
(169) |
Of course, we are interested in calculating the integral by the
Gauss-Legendre quadrature by Eq. (???)
The result is exact as the degree of the integrand
is no higher than . In comparison, the result by the
Newton-Cotes quadrature based on three equally spaced points
, and with is
. If the integrand is
of degree higher than , the result by the Gauss-Legendre
quadrature is no longer exact:
But this is still more accurate than the result by the Newton-Cotes
quadrature:
.
Here is the Matlab function to generate the Gauss points and the
coefficients for the Gauss-Legendre quadrature:
function [x,w]=GaussLegendre(n,method) % n: total number of points
% x and w are the Gauss nodes and weights
P=zeros(n+1); % coefficients of n+1 Legendre polynomials
b=zeros(n,1); % vector on right side for undetermined coefficients
w=zeros(n,1); % weights for the quadrature
P([1,2],1)=1; % coefficients of p_0(x)=1 and p_1(x)=x in first 2 rows
for k=1:n-1 % recursively generat remaining p_2(x) to p_{n+1}(x)
P(k+2,1:k+2)=((2*k+1)*[P(k+1,1:k+1) 0]-k*[0 0 P(k,1:k)])/(k+1);
end
% (i+1)th row of P contains coefficients of p_i(x) (i=0,...,n)
x=sort(roots(P(n+1,1:n+1))) % find all n+1 roots of p_{n+1}(x) (Gauss points)
switch method
% Method 1
dp=P(n+1,:).*[n:-1:0]; % coefficients of p'_{n+1}(x)
for i=1:n
t=x(i).^(n-1:-1:0); % p'_n(x_i)
t=dp(1:n)*t';
w(i)=2/(1-x(i)^2)/t/t; % weights for the quadrature
end
% method of undetermined coefficients: f(x)=x^k
A=zeros(n);
for k=1:n
A(k,:)=x.^(k-1); % matrix on left side
b(k)=(1-(-1)^k)/k; % vector on right side
end
% Method of undetermined coefficients: f(x)=p_k(x)
A=zeros(n);
for k=1:n % evaluate p_0(x)...p_{n-1}(x) at roots of p_n(x)
A(k,:)=polyval(P(k,1:k),x)'; % matrix on left side
end
b=[2;zeros(n-1,1)]; % vector on right side
w=inv(A)*b % find all weights
end