A1318 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A13 · Lesson 18 · Gaussian quadrature

Choosing where to sample, not just how to weight

The trapezoid and Simpson rules take equally spaced samples and choose only the weights. If you can evaluate the function anywhere (a field integral in a solver, an expected value over noise, an element in a finite-element program), you can choose the sample points too. Gauss showed that the best n points make the rule exact for every polynomial up to degree 2n−1, twice what equal spacing achieves. Two well-placed samples integrate any cubic exactly; five beat Simpson's rule with dozens. The magic points are the roots of the Legendre polynomials from A12.

  • The curve is a quartic, f(x)=1+bx+cx2+dx3+ex4, on [−1, 1]. The two dots are the 2-point Gauss nodes, ±1/3; the rule is f(−1/3)+f(1/3).
  • Move b, c and d: the Gauss estimate stays exact, because it's exact for every cubic. The 2-point trapezoid rule, f(−1)+f(1), is off whenever c isn't zero.
  • Only the x4 term (slider e) can fool two Gauss points. Three points would be exact through degree 5.

Predict

How many function evaluations does Gaussian quadrature need to integrate any polynomial of degree 9 exactly?

Name it

Gauss–Legendre rules

∫−11f(x)dx≈∑i=1nwif(xi)

with the nodes xi the roots of the Legendre polynomial Pn and positive weights wi:

nNodesWeightsExact through degree
1021
2±1/3=±0.577351, 13
30, ±3/5=±0.7746089, 59, 595
4±0.33998, ±0.861140.65215, 0.347857
50, ±0.53847, ±0.906180.56889, 0.47863, 0.236939

Why the Legendre roots

Divide any polynomial p of degree ≤2n−1 by Pn: p=qPn+r, with q and r of degree ≤n−1. The integral of qPn is zero by orthogonality, and qPn is also zero at the nodes, so the rule only has to integrate r exactly, which n points with the right weights can do.

Other intervals and weights

For [a, b], map x=b−a2t+a+b2:

∫abf(x)dx≈b−a2∑wif(b−a2ti+a+b2)

Other weight functions have their own rules: Gauss–Hermite for ∫e−x2f(x)dx, which gives expectations over Gaussian noise, and Gauss–Laguerre for ∫0∞e−xf(x)dx. Gauss–Kronrod rules add points to a Gauss rule so the difference between the two estimates gives an error estimate for free.

When not to use it

Gauss rules need f at irrational points, so they don't fit sampled data. For functions with a kink or singularity inside the interval, split the interval at the trouble spot first.

Worked example

Integrate ex from −1 to 1 with 2- and 3-point Gauss rules, and compare with Simpson's rule on 3 points.

Show the solution
  1. Exact value. 2sinh⁡1=2.3504024
  2. Two-point Gauss. e−0.57735+e0.57735=2.3426961 error 7.7×10−3.
  3. Three-point Gauss. 59(e−0.77460+e0.77460)+89=2.3503369 error 6.5×10−5.
  4. Simpson with 3 points. 13(e−1+4+e)=2.3620538 error 1.2×10−2.
  5. Compare. Simpson uses the same number of evaluations as the three-point rule and has 180 times its error.

Answer 2.3426961 with two Gauss points and 2.3503369 with three, against the exact 2.3504024; Simpson's 2.3620538 has 180 times the three-point error.

Worked example

Integrate x3 from 0 to 2 with the 2-point rule.

Show the solution
  1. Map the nodes. On [0, 2] the nodes map to 1∓0.57735, that is 0.42265 and 1.57735.
  2. Apply the rule. 2−02(0.422653+1.577353)=0.07550+3.92450=4.0000
  3. Check. That's exact, as it must be for a cubic.

Answer 4.0000, the exact value.

Worked example

Evaluate ∫−11x21−x2dx with the two-point Gauss–Chebyshev rule.

Show the solution
  1. The rule. For integrals with the weight 11−x2, the n-point Gauss–Chebyshev rule uses the nodes cos⁡(2k−1)π2n and the equal weights πn.
  2. Two points. With n = 2 the nodes are ±0.7071, so π2(0.5+0.5)=π2
  3. Why it's exact. That's exact, though the integrand blows up at both ends: the weight takes care of the singularity, and the rule needs only to integrate the smooth factor x2.
  4. Compare. Gauss–Legendre on the same integrand would converge slowly.

Answer π2, exactly.

Check

What does 2-point Gauss quadrature give for ∫−11x6dx?

Check

What does the 3-point Gauss rule give for ∫−11e2xdx?

Check

Through what polynomial degree is the 6-point Gauss–Legendre rule exact?

Check

What does the 2-point Gauss rule give for ∫02x4dx?

Check

Where does the positive 2-point node t=1/3 land on the interval [0, 2]?

Check

Why can't Gaussian quadrature be used directly on an oscilloscope's sampled waveform?

Check

The 3-point Gauss–Legendre rule has nodes 0 and ±3/5, with weights 89 and 59.

(a)

What does it give for ∫−11x10dx?

(b)

What is the exact value?

Check

Map the 2-point Gauss rule to [a,b] with x=a+b2+b−a2t.

Step 1

Where does the node t=1/3 land?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

How can n sample points integrate every polynomial up to degree 2n−1 exactly?

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.