38 lecture 25: Gaussian quadrature: nodes, weights; examles; extensions 3.5 Comuting Gaussian quadrature nodes and weights When first aroaching Gaussian quadrature, the comlicated characterization of the nodes and weights might seem like a significant drawback. For examle, if one aroximates an integral with an (n + )-oint Gaussian quadrature rule and finds the accuracy insufficient, one must comute an entirely new set of nodes and weights for a larger n from scratch. Many years ago, one would need to look u re-comuted nodes and weights for a given rule in book of mathematical tables, and one was thus limited to using values of n for which one could easily find tabulated values for the nodes and weights. However, in a landmark aer of 969, Gene Golub and John Welsch found a nice characterization of the nodes and weights in terms of a symmetric matrix eigenvalue roblem. Given the existence of excellent algorithms for comuting such eigenvalues, one can readily comute Gaussian quadrature nodes for arbitrary values of n. Some details of this derivation are left for a homework exercise, but we summarize the results here. One can show, via the discussion in Section 2.5, that, given values f (x) = and f (x) = the subsequent orthogonal olynomials can be generated via the three-term recurrence relation (3.4) f k+ (x) =x f k (x) a k f k (x) b k f k (x). The values of a,...,a n and b,...,b n follow from the Gram Schmidt rocess used in Section 2.5. Later we will also need the definition b := h, i = Z b a w(x) dx. G. H. Golub and J. H. Welsch, Calculation of Gauss Quadrature Rules, Math. Com. 23 (969) 22 23. In general, such algorithms require O(n 3 ) oerations to comute all eigenvalues and eigenvectors of an n n matrix; for the modest values of n most common in ractice (n in the tens or at most low hundreds), this exense is not onerous. Exloiting the structure of J n, this algorithm could be sed u to O(n 2 ). A good source for the values of {a k } and {b k } is Table. in Walter Gautschi s Orthogonal Polynomials, Oxford University Press, 24. Given a fixed value of n, collect the coefficients {a k } n k= and {b k } n k= and use them to oulate the Jacobi matrix 2 3 a b b a b2. (3.5) J n = b2...... 6... 4 an bn 7 5 bn a n The following theorem (whose roof is left for as a homework exercise) gives a ready way to comute the roots of f n+.
39 Theorem 3.9. Let {f j } n+ j= denote a sequence of monic orthogonal olynomials generated by the recurrence relation (3.4). Then l is a root of f n+ if and only if l is an eigenvalue of J n with corresonding eigenvector 2 (3.6) v(l) = 6 4 f (l) f (l)/ b f 2 (l)/ b b 2. f n (l)/ b b n 3. 7 5 Theorem 3.9 thus gives a convenient way to comute the nodes of a Gaussian quadrature rule. Given the nodes, one could comute the weights using either of the formulas (3.3) involving Lagrange basis functions. However, Golub and Welsch roved that these same weights could be extracted from the eigenvectors of the Jacobi matrix J n. Label the eigenvalues of J n as l < l < < l n and the corresonding eigenvectors, given by the formula (3.6), as v = v(l ), v = v(l ),..., v n = v(l n ). Then the weights for n + -oint Gaussian quadrature can be comuted as (3.7) = b kv j k 2, 2 Note: assumes (v j ) = f (l j )=. where k k 2 is the vector 2-norm. The formula (3.7) relies on the secific form of the eigenvector in (3.6). If the eigenvector is normalized differently (e.g., MATLAB s eigs routine gives unit eigenvectors, kv j k 2 =, then one should use the general formula (v j ) 2 (3.8) = b kv j k 2, 2 where (v j ) is the first entry in the eigenvector v j. 3.5. Examles of Gaussian Quadrature Let us examine four well-known Gaussian quadrature rules.
4 method interval, (a, b) weight, w(x) Gauss Legendre (, ) Gauss Chebyshev (, ) x 2 Gauss Laguerre (, ) e x Gauss Hermite (, ) e x2 The weight function lays an essential role here. For examle, a Gauss Chebyshev quadrature rule with n + = 5 oints will exactly integrate olynomials of degree 2n + = 9 times the weight function. Thus this rule will exactly integrate Z x 9 x 2 dx, but it will not exactly integrate Z x dx. This is a subtle oint that many students overlook when first learning about Gaussian quadrature. Examle 3.2. Gauss Legendre Quadrature When numerical analysts seak of Gaussian quadrature without further qualification, they tyically mean Gauss Legendre quadrature, i.e., quadrature with the weight function w(x) = (erhas over a transformed domain (a, b); see Section 3.5.2.) As discussed in Section 2.5., the orthogonal olynomials for this interval and weight are called Legendre olynomials. To construct a Gaussian quadrature rule with n + oints, determine the roots of the degree-(n + ) Legendre olynomial, then find the associated weights. First consider n =. The quadratic Legendre olynomial is f 2 (x) =x 2 /3, and from this olynomial one can derive the 2-oint quadrature rule that is exact for cubic olynomials, with roots ±/ 3. This agrees with the secial 2-oint rule derived in Section 3.4.. The values for the weights follow simly, w = w =, giving the 2-oint Gauss Legendre rule I n ( f )= f ( / 3)+ f (/ 3) that exactly integrates olynomials of degree 2n + = 3, i.e., all cubics. Recall that Simson s rule also exactly integrates cubics, but it requires three f evaluations, rather than the two f evaluations required of this rule.
4.6 n = 4.5.4.3.2..35.3.25.2.5..5 n = 8.5 - -.5.5 - -.5.5 - -.5.5.2..5 n = 6..8.6 n = 32.5 n = 64.4.3.25 n = 28 w.2 j.5.4.2..2..5 - -.5.5 - -.5.5 - -.5.5 For Gauss Legendre quadrature rules based on larger numbers of oints, we can comute the nodes and weights using the symmetric eigenvalue formulation discussed in Section 3.5. For this weight, one can show Figure 3.9: Nodes and weights of Gauss Legendre quadrature, for various values of n. In each case, the location of the vertical line indicates x j, while the height of the line shows. a k =, k =,,... ; b = 2; b k = k2 4k 2, k =, 2, 3,.... Figure 3.9 shows the nodes and weights for six values of n, as comuted via the eigenvalue roblem. Notice that the oints are not uniformly saced, but are slightly more dense at the ends of the interval. Moreover, the weights are smaller at these ends of the interval. The table below shows nodes and weights for n = 4, as comuted in MATLAB. j nodes, x j weights,.9679845938664.2369268855689.53846935683.47862867499366 2..568888888888889 3.53846935683.47862867499367 4.9679845938664.2369268855689 Examle 3.3. Gauss Chebyshev quadrature Another oular class of Gaussian quadrature rules use as their nodes the roots of the Chebyshev olynomials. The standard degree-
42 k Chebyshev olynomial is defined as T k (x) =cos(k cos x), which can be generated by the recurrence relation T k+ (x) =2xT k (x) T k (x). with T (x) = and T (x) =x. These Chebyshev olynomials are orthogonal on (, ) with resect to the weight function w(x) = x 2. The degree-(n + ) Chebyshev olynomial has the roots x j = cos (j + /2), j =,..., n. n + In this case all the weights work out to be identical; one can show = n + for all j =,... n. Figure 3. shows these nodes and weights. One can also define the monic Chebyshev olynomials according to the recurrence (3.4) with a k =, k =,,... ; See Süli and Mayers, Problem.4 for a sketch of a roof. b = ; b = /2; b k = /4, k = 2, 2, 3,.... The resulting olynomials are scaled versions of the usual Chebyshev olynomials T k+ (x), and thus have the same roots. Again, we emhasize that the weight function lays a crucial role: the Gauss Chebyshev rule based on n + interolation nodes will exactly comute integrals of the form Z (x) dx x 2 for all 2 P 2n+. For a general integral Z f (x) dx. x 2 the quadrature rule should be imlemented as I n ( f )= n  f (x j ); j= Note that the / x 2 comonent of the integrand is not evaluated here; its influence has already been incororated into the weights { }.
43.7 n = 4.6.5.4.3.2..4.3.2. n = 8.5.2 n = 6 - -.5.5 - -.5.5 - -.5.5..5. n = 32.5 n = 64.25 n = 28.8.4.2.6.3.5.4.2..2..5 - -.5.5 - -.5.5 - -.5.5 The Chebyshev weight function w(x) = /( x 2 ) blows u at ±, so if the integrand f does not balance this growth, adative Newton Cotes rules will likely have to lace many interolation nodes near these singularities to achieve decent accuracy, while Gauss Chebyshev quadrature has no roblems. Moreover, in this imortant case, the nodes and weights are trivial to comute, thus allaying the need to solve the eigenvalue roblem. It is worth ointing out that Gauss Chebyshev quadrature is quite different than Clenshaw Curtis quadrature. Though both use Chebyshev oints as interolation nodes, only Gauss Chebyshev incororates the weight function w(x) =( x 2 ) /2 in the weights { }. Thus Clenshaw Curtis is more aroriately comared to Gauss Legendre quadrature. Since the Clenshaw Curtis method is not a Gaussian quadrature formula, it will generally be exact only for all 2 P n, rather than all 2 P 2n+. Figure 3.: Nodes and weights of Gauss Chebyshev quadrature, for various values of n. In each case, the location of the vertical line indicates x j, while the height of the line shows. The nodes, roots of Chebyshev olynomials, cluster toward the end of the intervals; the weights are the same for all the nodes, = /(n + ). Examle 3.4. Gauss Laguerre quadrature The Laguerre olynomials form a set of orthogonal olynomials over (, ) with the weight function w(x) = e x. The accomanying quadrature rule aroximates integrals of the form Z f (x)e x dx. The recurrence (3.4) uses the coefficients
44 n = 4 n = 8 n = 6 log - -2 log - -2 log - -2-25 -25-25 -2-2 -2-2 -2-2 a k = 2k +, k =,,... ; b = ; b k = k 2, k =, 2, 3,.... Figure 3. shows the nodes and weights for several values of n. Since the domain of integration (, ) is infinite, the quadrature nodes x j get larger and larger. As the nodes get larger, the corresonding weights decay raidly. When < 5, it becomes difficult to reliably comute the weights by solving the Jacobi matrix eigenvalue roblem. To get the small weights given here, we have used Chebfun s lagts routine routine, which uses a more efficient algorithm of Glaser, Liu, and Rokhlin (27). Figure 3.: Nodes and weights of Gauss Laguerre quadrature, for various values of n. In each case, the location of the vertical line indicates x j, while the height of the line shows log. Note that the horizontal axis is scaled logarithmically. As n increases the quadrature rule includes larger and larger nodes to account for the infinite domain of integration; however, the weights are excetionally small for the larger nodes. For examle for n = 6, w 6 23. Examle 3.5. Gauss Hermite quadrature The Hermite olynomials are orthogonal olynomials over (, ) with the weight function w(x) =e x2. This quadrature rule aroximates integrals of the form Z f (x)e x2 dx. The Hermite olynomials can be generated using the recurrence (3.4) with coefficients a k =, k =,,... ; b = ; b k = k/2, k =, 2, 3,.... Figure 3.2 shows nodes and weights for various values of n. Though the interval of integration is infinite, the nodes do not grow as raidly as for Gauss Laguerre quadrature, since the Hermite weight w(x) =e x2 decays more raidly than the Laguerre weight w(x) = e x. (Again, the nodes and weights in the figure were comuted with Chebfun s imlementation of the Glaser, Liu, and Rokhlin algorithm.)
45 n = 4 n = 8 n = 6 log - log - log - -6-4 -2 2 4 6-6 -4-2 2 4 6-6 -4-2 2 4 6 3.5.2 Changing variables to transform domains One notable drawback of Gaussian quadrature is the need to recomute (or look u) the requisite weights and nodes. If one has a quadrature rule for the interval [c, d], and wishes to adat it to the interval [a, b], there is a simle change of variables rocedure to eliminate the need to recomute the nodes and weights from scratch. Let t be a linear transformation taking [c, d] to [a, b], b a t(x) =a + (x c) d c Figure 3.2: Nodes and weights of Gauss Hermite quadrature, for various values of n. In each case, the location of the vertical line indicates x j, while the height of the line shows log. Contrast this lot to Figure 3.. Though the domain of integration is infinite in both cases, the weight function here, e x2, decays much more raidly than e x, exlaining why the largest nodes are smaller than seen in Figure 3. for Gauss Laguerre quadrature. with inverse t : [a, b]! [c, d], d t (y) =c + b Then we have Z b a f (x)w(x) dx = Z t (b) b = d t (a) The quadrature rule for [a, b] takes the form for b b = d bi( f )= c (y a). a f (t(x))w(t(x))t (x) dx Z a d f (t(x))w(t(x)) dx. c c n  b f (bx j ), j= a w c j, bx j = t (x j ), where {x j } n j= and {} n j= are the nodes and weights for the quadrature rule on [c, d]. Be sure to note how this change of variables alters the weight function. The transformed rule will now have a weight function w(t(x)) = w(a +(b a)(x c)/(d c)), not simly w(x). To make this concrete, consider Gauss Chebyshev quadrature, which uses the weight function w(x) =( x 2 ) /2 on
46 [, ]. If one wishes to integrate, for examle, R x( x2 ) /2 dx, it is not sufficient just to use the change of variables formula described here. To comute the desired integral, one would have to adjust the nodes and weights to accommodate w(x) =( x 2 ) /2 on [, ]. Comosite rules Emloying this change of variables technique, it is simle to devise a method for decomosing the interval of integration into smaller regions, over which Gauss quadrature rules can be alied. (The most straightforward alication is to adjust the Gauss Legendre quadrature rule, which avoids comlications induced by the weight function, since w(x) = in this case.) Such techniques can be used to develo Gaussian-based adative quadrature rules. 3.5.3 Gauss Radau and Gauss-Lobatto quadrature Some alications make it necessary or convenient to force one or both of the end oints of the interval of integration to be among the quadrature oints. Such methods are known as Gauss Radau and Gauss Lobatto quadrature rules, resectively; rules based on n + interolation oints exactly integrate all olynomials in P 2n or P 2n : each quadrature node that we fix decreases the otimal order by one.