Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
nb 1
Gauss-Legendre Integration
Numerical integration always has the same form. To approximate an integral Ÿa f HxL „ x , you pick some points x1 , …, xn
b
So far, all the integration methods we have used were based on evenly spaced points. Gauss discovered that much more
accurate methods can be derived if you just use the right unequally-spaced points.
A good way to create a method of numerical integration is to find a scheme that gives exactly correct results for polynomi-
als 1, x, x2 , …, xn . That scheme will usually give pretty accurate results for any function. The higher n is, the more
accurate is the method.
First a little detour. In the following sections, we will be presenting methods for integrals of the form Ÿ-1 f HxL „ x . However
1
if we can do these integrals, we can do any integral at all using substitution. For example:
‡ t „ t = ÅÅÅÅÅÅÅÅÅ ‡ Hx + 1L „ Ñ
3 1
2 27 2
0 8 -1
Let's look for 1 < x1 < x2 < 1 and numbers A1 and A2 such that
-1
We will find values for xi and Ai such that the approximation is exact for f HxL = 1, x, x2 and x3 :
2 = A1 + A2
0 = A1 x1 + A2 x2
ÅÅÅÅ23 = A1 x1 2 + A2 x2 2
0 = A1 x1 3 + A2 x2 3
i -1 yz ij 1 yz
‡ f HxL „ x º f jjj ÅÅÅÅÅÅÅÅ z j ÅÅÅÅÅ zz.
è!!!ÅÅÅÅÅ z + f j ÅÅÅÅÅÅÅÅ
è!!!
1
-1 k 3 { k 3 {
Out[22]= 1.93582
Out[23]= 2.22144
The two-point Gauss-Legendre method has an error of 3.2%; the two-point midpoint method has an error of 11%.
If we used n points and n weights we could hope to integrate polynomials up to x2 n exactly, and we could use the property
to construct the points x1 , …, xn and weights A1 , …, An . This method his called Gauss-Legendre Integration. The actual
methods used to find the points and the weights is slightly more complicated and requires solving polynomial equations of
high degree. However the work has been done, and we can look it up on the website below. You may find other sources,
even Mathematica. Whatever sources you use, the points and weights should be given with 15 digit accuracy.
http://www.math.ntnu.no/num/nnm/Program/Numlibc/gauss_co.c
Let's try the integral above with four points, and compare the result to the midpoint method with four panels.
The parameters are given in order 8xi , Ai <. Only two xi values are given, because the xi are symmetric and the weight at a
negative point is the same as the weight at a positive point.
gaussEstimate =
Sum@gc4@@i, 2DD HPi ê 2 Cos@−Pi gc@@i, 1DD ê 2D + Pi ê 2 Cos@Pi gc4@@i, 1DD ê 2DL, 8i, 1, 2<D
In[25]:=
Out[25]= 1.99998
Out[26]= 2.05234
Now let's try the 24 point estimate. Again, only 12 points and 12 weights are given; the other 12 come from symmetry.
In[29]:= Sum@Hf@−gc24@@i, 1DDD + f@gc24@@i, 1DDDL gc24@@i, 2DD, 8i, 12<D êê InputForm
Out[29]//InputForm=
1.9999999999999933
We can map the interval H-1, 1L to the interval Ha, bL with the transformation x = ÅÅÅÅ
a+b
2
b-a
ÅÅÅÅÅÅ + ÅÅÅÅ b-a
ÅÅÅÅÅÅ t, dx = ÅÅÅÅ
2
ÅÅÅÅÅÅ dt. Then
2
i a+b y
‡ f HxL „ x = ‡ f jj ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ + ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ tzz „ t
b-a
k 2
b-a
{
b 1
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
a -1 2 2
If we have Gauss-Legendre points xi and weights Ai , then the Gauss-Legendre approximation is:
a i
2 2
Thus we can write a general Gauss-Legendre integrator, where gc is the array of Gauss-Legendre coefficients on the
positive side of 0:
j
jfA gc@@i, 1DDEz
z,
b−a a+b b−a
2 k {
SumAgc@@i, 2DD − gc@@i, 1DDE + fA +
8i, 1, Length@gcD<E
2 2 2 2
Let's use this method to integrate Ÿ0 x cos x „ x using 24 points. The exact value is -2.
p
Out[32]//InputForm=
-1.999999999999979
ü Error Estimates
sufficient order on the closed domain of integration. The error estimate for the approximation of Ÿa f HxL „ x using n points
We can estimate the error in the Gauss-Legendre approximation, provided our integrand has continuous derivatives of
b
is:
22 n+1 Hn!L4
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ yH2 nL HqL
H2 n + 1L@H2 nL!D3
Error = ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
for some q œ @a, bD. Note that the coefficient of yH2 nL HqL rapidly decreases to 0 as n increases, so if the derivatives yH2 nL HqL do
not grow too fast then the Gauss-Legendre estimates approach the value of the integral as n Ø ¶. In particular, if the
derivatives are bounded then the estimates approach the integral. Of course, in a concrete problem, you have to come up
with actual estimates of all the quantities involved.
gauss_quad.nb 4
Example: Ÿ0 sin x „ x. Since all the derivatives of sin x have absolute value less than 1, the error in the n-point Gauss-Leg-
p
22 n+1 Hn!L4
H2 n+1L@H2 nL!D3
endre approximation will be less than ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ
ÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅÅ . If n = 24, this error bound is:
n = 24;
22 n+1 Hn !L4
In[33]:=
êê N
H2 n + 1L HH2 nL !L3
accuracy. Let's see what we get if we try to estimate Ÿ0 sin x „ x using the 20-point Gauss-Legendre method and 16-digit
The theoretical error is much smaller than the error due to round-off. Using floating point arithmetic limits us to 16-digit
p
Out[36]//InputForm=
1.9999999999999933