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 , 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, , on [−1, 1]. The two dots are the 2-point Gauss nodes, ; the rule is .
- Move b, c and d: the Gauss estimate stays exact, because it's exact for every cubic. The 2-point trapezoid rule, , is off whenever c isn't zero.
- Only the 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?
Five: an n-point Gauss rule is exact through degree , and . An equally spaced rule with free weights would need 10 points (Newton–Cotes), and those weights turn negative and unstable at high order.
Name it
Gauss–Legendre rules
with the nodes the roots of the Legendre polynomial and positive weights :
| n | Nodes | Weights | Exact through degree |
|---|---|---|---|
| 1 | 0 | 2 | 1 |
| 2 | 1, 1 | 3 | |
| 3 | 0, | , , | 5 |
| 4 | ±0.33998, ±0.86114 | 0.65215, 0.34785 | 7 |
| 5 | 0, ±0.53847, ±0.90618 | 0.56889, 0.47863, 0.23693 | 9 |
Why the Legendre roots
Divide any polynomial p of degree by : , with q and r of degree . The integral of is zero by orthogonality, and 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 :
Other weight functions have their own rules: Gauss–Hermite for , which gives expectations over Gaussian noise, and Gauss–Laguerre for . 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 from −1 to 1 with 2- and 3-point Gauss rules, and compare with Simpson's rule on 3 points.
Show the solution
- Exact value.
- Two-point Gauss. error .
- Three-point Gauss. error .
- Simpson with 3 points. error .
- 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 from 0 to 2 with the 2-point rule.
Show the solution
- Map the nodes. On [0, 2] the nodes map to , that is 0.42265 and 1.57735.
- Apply the rule.
- Check. That's exact, as it must be for a cubic.
Answer 4.0000, the exact value.
Worked example
Evaluate with the two-point Gauss–Chebyshev rule.
Show the solution
- The rule. For integrals with the weight , the n-point Gauss–Chebyshev rule uses the nodes and the equal weights .
- Two points. With n = 2 the nodes are , so
- 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 .
- Compare. Gauss–Legendre on the same integrand would converge slowly.
Answer , exactly.
Check
What does 2-point Gauss quadrature give for ?
Check
What does the 3-point Gauss rule give for ?
Check
Through what polynomial degree is the 6-point Gauss–Legendre rule exact?
Check
What does the 2-point Gauss rule give for ?
Check
Where does the positive 2-point node 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 , with weights and .
(a)
What does it give for ?
(b)
What is the exact value?
Check
Map the 2-point Gauss rule to with .
Step 1
Where does the node 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°.
Step 2
What does the rule give for ?
Explain why
How can n sample points integrate every polynomial up to degree exactly?
A rule with n points has 2n free choices: n weights and n locations, and polynomials up to degree have 2n coefficients, so the count works out. Gauss's choice of locations is the roots of the Legendre polynomial . Any polynomial p of degree up to can be split as with q and r of degree below n. The part integrates to zero, because is orthogonal to every lower-degree polynomial, and it's also zero at every node, so the rule correctly gives it zero. What's left, r, has degree below n, and n points with suitable weights integrate such polynomials 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.