where a and b = the limits of integration and b − a = the width of the integration interval.
Because the trapezoidal rule must pass through the end points, there are cases such as Fig. 20.3a where the formula results in a large error.
Now, suppose that the constraint of fixed base points was removed and we were free to evaluate the area under a straight line joining any two points on the curve. By positioning
these points wisely, we could define a straight line that would balance the positive and neg- ative errors. Hence, as in Fig. 20.3b, we would arrive at an improved estimate of the integral.
Gauss quadrature is the name for a class of techniques to implement such a strategy.
The particular Gauss quadrature formulas described in this section are called Gauss- Legendre
formulas. Before describing the approach, we will show how numerical integra- tion formulas such as the trapezoidal rule can be derived using the method of undetermined
coefficients. This method will then be employed to develop the Gauss-Legendre formulas.
20.3.1 Method of Undetermined Coefficients
In Chap. 19, we derived the trapezoidal rule by integrating a linear interpolating polynomial and by geometrical reasoning. The method of undetermined coefficients offers a third ap-
proach that also has utility in deriving other integration techniques such as Gauss quadrature.
f x
a
b x
f x
x
FIGURE 20.3
a Graphical depiction of the trapezoidal rule as the area under the straight line joining fixed end points. b An improved integral estimate obtained by taking the area under the straight line
passing through two intermediate points. By positioning these points wisely, the positive and negative errors are better balanced, and an improved integral estimate results.
To illustrate the approach, Eq. 20.10 is expressed as I ∼
= c f a + c
1
f b
20.11
where the c’s = constants. Now realize that the trapezoidal rule should yield exact results when the function being integrated is a constant or a straight line. Two simple equations
that represent these cases are y = 1 and y = x Fig. 20.4. Thus, the following equalities should hold:
c + c
1
=
b−a 2
−b−a 2
1 d x and
−c b − a
2 + c
1
b − a 2
=
b−a 2
−b−a 2
x d x
20.3 GAUSS QUADRATURE 505
x y
y ⫽ 1
a ⫺b ⫺ a
2
⫺b ⫺ a 2
x y
⫽ x y
b b
⫺ a 2
b ⫺ a
2
FIGURE 20.4
Two integrals that should be evaluated exactly by the trapezoidal rule: a a constant and b a straight line.
or, evaluating the integrals, c
+ c
1
= b − a and
−c b
− a 2
+ c
1
b − a
2 = 0
These are two equations with two unknowns that can be solved for c
= c
1
= b
− a 2
which, when substituted back into Eq. 20.11, gives I
= b
− a 2
f a +
b − a
2 f b
which is equivalent to the trapezoidal rule.
20.3.2 Derivation of the Two-Point Gauss-Legendre Formula
Just as was the case for the previous derivation of the trapezoidal rule, the object of Gauss quadrature is to determine the coefficients of an equation of the form
I ∼ = c
f x +
c
1
f x
1
20.12
where the c’s = the unknown coefficients. However, in contrast to the trapezoidal rule that used fixed end points a and b, the function arguments x
and x
1
are not fixed at the end points, but are unknowns Fig. 20.5. Thus, we now have a total of four unknowns that
must be evaluated, and consequently, we require four conditions to determine them exactly. Just as for the trapezoidal rule, we can obtain two of these conditions by assuming
that Eq. 20.12 fits the integral of a constant and a linear function exactly. Then, to arrive at the other two conditions, we merely extend this reasoning by assuming that it also fits the
integral of a parabolic y = x
2
and a cubic y = x
3
function. By doing this, we determine
f x
f x
f x
1
⫺1 1
x
1
x x
FIGURE 20.5
Graphical depiction of the unknown variables x and x
1
for integration by Gauss quadrature.
all four unknowns and in the bargain derive a linear two-point integration formula that is exact for cubics. The four equations to be solved are
c + c
1
=
1 −1
1 d x = 2
20.13
c x
+ c
1
x
1
=
1 −1
x d x = 0
20.14
c x
2
+ c
1
x
2 1
=
1 −1
x
2
d x =
2 3
20.15
c x
3
+ c
1
x
3 1
=
1 −1
x
3
d x = 0
20.16
Equations 20.13 through 20.16 can be solved simultaneously for the four unknowns. First, solve Eq. 20.14 for c
1
and substitute the result into Eq. 20.16, which can be solved for x
2
= x
2 1
Since x and x
1
cannot be equal, this means that x = −x
1
. Substituting this result into
Eq. 20.14 yields c = c
1
. Consequently from Eq. 20.13 it follows that
c = c
1
= 1 Substituting these results into Eq. 20.15 gives
x = −
1 √
3 = −0.5773503 . . .
x
1
= 1
√ 3
= 0.5773503 . . . Therefore, the two-point Gauss-Legendre formula is
I = f
−1 √
3 + f
1 √
3
20.17
Thus, we arrive at the interesting result that the simple addition of the function values at x
= −1 √
3 and 1 √
3 yields an integral estimate that is third-order accurate. Notice that the integration limits in Eqs. 20.13 through 20.16 are from −1 to 1. This
was done to simplify the mathematics and to make the formulation as general as possible. A simple change of variable can be used to translate other limits of integration into this
form. This is accomplished by assuming that a new variable x
d
is related to the original variable x in a linear fashion, as in
x = a
1
+ a
2
x
d
20.18
If the lower limit, x = a, corresponds to x
d
= −1, these values can be substituted into Eq. 20.18 to yield
a = a
1
+ a
2
−1
20.19
Similarly, the upper limit, x = b, corresponds to x
d
= 1, to give b
= a
1
+ a
2
1
20.20 20.3 GAUSS QUADRATURE
507
Equations 20.19 and 20.20 can be solved simultaneously for a
1
= b
+ a 2
and a
2
= b
− a 2
20.21
which can be substituted into Eq. 20.18 to yield x
= b
+ a + b − ax
d
2
20.22
This equation can be differentiated to give d x
= b
− a 2
d x
d
20.23
Equations 20.22 and 20.23 can be substituted for x and d x , respectively, in the equation to be integrated. These substitutions effectively transform the integration interval without
changing the value of the integral. The following example illustrates how this is done in practice.
EXAMPLE 20.3 Two-Point Gauss-Legendre Formula
Problem Statement. Use Eq. 20.17 to evaluate the integral of
f x = 0.2 + 25x − 200x
2
+ 675x
3
− 900x
4
+ 400x
5
between the limits x = 0 to 0.8. The exact value of the integral is 1.640533.
Solution. Before integrating the function, we must perform a change of variable so that
the limits are from −1 to +1. To do this, we substitute a = 0 and b = 0.8 into Eqs. 20.22
and 20.23 to yield x
= 0.4 + 0.4x
d
and d x
= 0.4dx
d
Both of these can be substituted into the original equation to yield
0.8
0.2 + 25x − 200x
2
+ 675x
3
− 900x
4
+ 400x
5
d x =
1 −1
[0.2 + 250.4 + 0.4x
d
− 2000.4 + 0.4x
d 2
+ 6750.4 + 0.4x
d 3
− 9000.4 + 0.4x
d 4
+ 4000.4 + 0.4x
d 5
]0.4d x
d
Therefore, the right-hand side is in the form that is suitable for evaluation using Gauss quadrature. The transformed function can be evaluated at x
d
= −1 √
3 as 0.516741 and at x
d
= 1 √
3 as 1.305837. Therefore, the integral according to Eq. 20.17 is 0.516741 + 1.305837 = 1.822578, which represents a percent relative error of −11.1. This result is
comparable in magnitude to a four-segment application of the trapezoidal rule or a single application of Simpson’s 13 and 38 rules. This latter result is to be expected because
Simpson’s rules are also third-order accurate. However, because of the clever choice of base points, Gauss quadrature attains this accuracy on the basis of only two function
evaluations.
20.3.3 Higher-Point Formulas
Beyond the two-point formula described in the previous section, higher-point versions can be developed in the general form
I ∼ = c
f x +
c
1
f x
1
+ · · · + c
n− 1
f x
n− 1
20.24
where n = the number of points. Values for c’s and x’s for up to and including the six-point formula are summarized in Table 20.1.
EXAMPLE 20.4 Three-Point Gauss-Legendre Formula
Problem Statement. Use the three-point formula from Table 20.1 to estimate the integral
for the same function as in Example 20.3. Solution.
According to Table 20.1, the three-point formula is I =
0.5555556 f −0.7745967 + 0.8888889 f 0 + 0.5555556 f 0.7745967 which is equal to
I = 0.2813013 + 0.8732444 + 0.4859876 = 1.640533
which is exact.
20.3 GAUSS QUADRATURE 509
TABLE 20.1 Weighting factors and function arguments used in Gauss-Legendre formulas.
Weighting Function
Truncation Points
Factors Arguments
Error
1 c
= 2
x =
0.0 ∼
=
f
2
ξ 2
c =
1 x
= − 1
√ 3
∼ =
f
4
ξ c
1
= 1
x
1
= 1
√ 3
3 c
= 59 x
= − 35
∼ =
f
6
ξ c
1
= 89
x
1
= 0.0
c
2
= 59
x
2
= 35
4 c
= 18 −
√ 30 36
x = −
525 + 70 √
3035 ∼
=
f
8
ξ c
1
= 18 +
√ 30 36
x
1
= − 525 − 70
√ 3035
c
2
= 18 + √
30 36 x
2
= 525 − 70
√ 3035
c
3
= 18 − √
30 36 x
3
= 525 + 70
√ 3035
5 c
= 322 − 13 √
70 900 x
= − 245 + 14
√ 7021
∼ =
f
10
ξ c
1
= 322 + 13
√ 70 900
x
1
= − 245 − 14
√ 7021
c
2
= 128225 x
2
= 0.0 c
3
= 322 + 13 √
70 900 x
3
= 245 − 14
√ 7021
c
4
= 322 − 13 √
70 900 x
4
= 245 + 14
√ 7021
6 c
= 0.171324492379170 x
= −0.932469514203152 ∼
=
f
12
ξ c
1
= 0.360761573048139
x
1
= − 0.661209386466265
c
2
= 0.467913934572691
x
2
= − 0.238619186083197
c
3
= 0.467913934572691
x
3
= 0.238619186083197
c
4
= 0.360761573048131
x
4
= 0.661209386466265
c
5
= 0.171324492379170
x
5
= 0.932469514203152
Because Gauss quadrature requires function evaluations at nonuniformly spaced points within the integration interval, it is not appropriate for cases where the function is unknown.
Thus, it is not suited for engineering problems that deal with tabulated data. However, where the function is known, its efficiency can be a decided advantage. This is particularly true
when numerous integral evaluations must be performed.
20.4 ADAPTIVE QUADRATURE
Although Romberg integration is more efficient than the composite Simpson’s 13 rule, both use equally spaced points. This constraint does not take into account that some func-
tions have regions of relatively abrupt changes where more refined spacing might be re- quired. Hence, to achieve a desired accuracy, fine spacing must be applied everywhere
even though it is only needed for the regions of sharp change. Adaptive quadrature meth- ods remedy this situation by automatically adjusting the step size so that small steps are
taken in regions of sharp variations and larger steps are taken where the function changes gradually.
20.4.1 MATLAB M-file:
quadadapt
Adaptive quadrature methods accommodate the fact that many functions have regions of
high variability along with other sections where change is gradual. They accomplish this by adjusting the step size so that small intervals are used in regions of rapid variations
and larger intervals are used where the function changes gradually. Many of these tech- niques are based on applying the composite Simpson’s 13 rule to subintervals in a fash-
ion that is very similar to the way in which the composite trapezoidal rule was used in Richardson extrapolation. That is, the 13 rule is applied at two levels of refinement, and
the difference between these two levels is used to estimate the truncation error. If the truncation error is acceptable, no further refinement is required, and the integral estimate
for the subinterval is deemed acceptable. If the error estimate is too large, the step size is refined and the process repeated until the error falls to acceptable levels. The total inte-
gral is then computed as the summation of the integral estimates for the subintervals.
The theoretical basis of the approach can be illustrated for an interval x = a to x = b
with a width of h
1
= b ⫺ a. A first estimate of the integral can be estimated with Simpson’s 13 rule:
I h
1
= h
1
6 [ f a
+ 4 f c + f b]
20.25
where c = a ⫹ b兾2.
As in Richardson extrapolation, a more refined estimate can be obtained by halving the step size. That is, by applying the composite Simpson’s 13 rule with n
= 4: I h
2
= h
2
6 [ f a
+ 4 f d + 2 f c + 4 f e + f b]
20.26
where d = a + c兾2, e = c + b兾2, and h
2
= h
1
兾2. Because both Ih
1
and Ih
2
are estimates of the same integral, their difference pro- vides a measure of the error. That is,
E ∼ = I h
2
− I h
1
20.27
In addition, the estimate and error associated with either application can be represented generally as
I = I h + Eh
20.28
where I ⫽ the exact value of the integral, Ih ⫽ the approximation from an n-segment application of the Simpson’s 13 rule with step size h ⫽ b ⫺ a兾n, and Eh ⫽ the corre-
sponding truncation error. Using an approach similar to Richardson extrapolation, we can derive an estimate in
the error of the more refined estimate Ih
2
as a function of the difference between the two integral estimates:
Eh
2
= 1
15 [I h
2
− I h
1
]
20.29
The error can then be added to I h
2
to generate an even better estimate: I
= I h
2
+ 1
15 [I h
2
− I h
1
]
20.30
This result is equivalent to Boole’s rule Table 19.2. The equations just developed can now be combined into an efficient algorithm. Fig-
ure 20.6 presents an M-file function that is based on an algorithm originally developed by Cleve Moler 2004.
The function consists of a main calling function
quadapt
along with a recursive func- tion
qstep
that actually performs the integration. The main calling function
quadapt
is passed the function
f
and the integration limits
a
and
b
. After setting the tolerance, the function evaluations required for the initial application of Simpson’s 13 rule Eq. 20.25
are computed. These values along with the integration limits are then passed to
qstep.
Within
qstep
, the remaining step sizes and function values are determined, and the two integral estimates Eqs. 20.25 and 20.26 are computed.
At this point, the error is estimated as the absolute difference between the integral estimates. Depending on the value of the error, two things can then happen:
1. If the error is less or equal to the tolerance
tol
, Boole’s rule is generated; the func- tion terminates and passes back the result.
2. If the error is larger than the tolerance,
qstep
is invoked twice to evaluate each of the two subintervals of the current call.
The two recursive calls in the second step represent the real beauty of this algorithm. They just keep subdividing until the tolerance is met. Once this occurs, their results are
passed back up the recursive path, combining with the other integral estimates along the way. The process ends when the final call is satisfied and the total integral is evaluated and
returned to the main calling function.
It should be stressed that the algorithm in Fig. 20.6 is a stripped-down version of the
quad
function, which is the professional root-location function employed in MATLAB. Thus, it does not guard against failure such as cases where integrals do not exist. Nevertheless, it works
just fine for many applications, and certainly serves to illustrate how adaptive quadrature
20.4 ADAPTIVE QUADRATURE 511