Gaussian Quadrature: A Masterclass on Optimal Integration
Discover the paradigm-shifting technique that achieves unbelievable accuracy by asking a simple question: what if we could choose the perfect places to sample our function?
The Flaw in Equal Spacing
In our journey through numerical integrationThe process of finding an approximate value for a definite integral, essential when the exact mathematical solution is impossible or impractical to find., we've mastered powerful techniques like the Trapezoidal and Simpson's Rules. They all share a common, intuitive approach: slice an interval into equally-spaced segments. It feels natural, but is it optimal? What if I told you that by giving up the "comfort" of equal spacing and instead choosing our sample points with mathematical genius, we could achieve a level of accuracy that seems almost impossible?
This is the revolutionary idea behind Gaussian Quadrature. The Newton-Cotes methods (Trapezoidal, Simpson's, etc.) work with a handicap: their sample points are fixed. Their only "freedom" is to choose the weights for those points. Gaussian Quadrature unshackles itself from this constraint. It treats both the sample points and their weights as variables to be optimized.
By finding the absolute best possible locations to sample a function, Gaussian Quadrature can achieve the same accuracy as a Newton-Cotes rule with significantly fewer function evaluations. When every function evaluation is computationally expensive—like in a complex physics simulation—this is a game-changer.
The Core Idea: The Method of Undetermined Coefficients
How do we find these "magic" points and weights? The strategy is to choose them such that our formula gives the exact result for the highest possible degree of polynomial. Let's see this in action by deriving the simplest, most famous example: the **two-point Gauss-Legendre formula**.
Our goal is to find an integration formula of the form:
$$ \int_{-1}^{1} f(x) dx \approx w_1 f(x_1) + w_2 f(x_2) $$We have four unknowns to solve for: two weights ($w_1, w_2$) and two points ($x_1, x_2$). With four degrees of freedomThe number of independent variables or parameters that can be freely chosen in a mathematical system. Here, we can choose the values of w1, w2, x1, and x2., we can force this formula to be exact for polynomials up to degree 3. So, we make it exact for $f(x)=1, f(x)=x, f(x)=x^2,$ and $f(x)=x^3$ on the standard interval $[-1, 1]$.
- $f(x)=1: \int_{-1}^{1} 1 dx = 2 \implies w_1 + w_2 = 2$
- $f(x)=x: \int_{-1}^{1} x dx = 0 \implies w_1 x_1 + w_2 x_2 = 0$
- $f(x)=x^2: \int_{-1}^{1} x^2 dx = \frac{2}{3} \implies w_1 x_1^2 + w_2 x_2^2 = \frac{2}{3}$
- $f(x)=x^3: \int_{-1}^{1} x^3 dx = 0 \implies w_1 x_1^3 + w_2 x_2^3 = 0$
Solving this system of (non-linear) equations yields a beautiful, symmetric result:
$$ w_1 = 1, \quad w_2 = 1 $$ $$ x_1 = -\frac{1}{\sqrt{3}}, \quad x_2 = +\frac{1}{\sqrt{3}} $$This is incredible! The two-point Gauss-Legendre formula is exact for all polynomials of degree 3 or less. For comparison, Simpson's 1/3 Rule needs three points to achieve the same degree of precision.
The Role of Legendre Polynomials
Solving these systems of equations becomes impossible for higher orders. The genius of Carl Friedrich Gauss was to prove that the optimal points, $x_i$, are the roots of a special class of polynomials called **Legendre Polynomials**. The corresponding weights, $w_i$, can then be calculated from these roots. While the theory is deep, the results can be pre-calculated and looked up in a table.
The Gauss Quadrature Visualizer
Let's visualize the power of optimal point selection. This lab compares the accuracy of Simpson's 1/3 Rule (a Newton-Cotes formula) with the Gauss-Legendre formula that uses the same number of function evaluations. Notice how the Gaussian points are strangely spaced—they are the mathematically optimal locations!
Integration Showdown: Newton-Cotes vs. Gauss
Solving a Numerical Problem
The "magic numbers" for the Gauss points and weights are defined on the interval $[-1, 1]$. To use them on a real-world problem on an interval $[a, b]$, we must first perform a change of variables.
Problem 1: Two-Point Gauss-Legendre Quadrature
Question: Use the two-point Gauss-Legendre formula to estimate the integral of $f(x) = \frac{1}{1+x^2}$ from $x=0$ to $x=1$.
Step 1: Get Standard Points and Weights
From a lookup table for n=2, we have:
$w_1 = 1, w_2 = 1$
$t_1 = -0.57735, t_2 = 0.57735$ (where $t$ is the variable on $[-1, 1]$)
Step 2: Change of Interval
Our interval is $[a, b] = [0, 1]$. We need to map our standard points $t$ to our problem points $x$ using the transformation:
$$ x = \frac{b-a}{2}t + \frac{b+a}{2} $$
$$ x = \frac{1-0}{2}t + \frac{1+0}{2} = 0.5t + 0.5 $$
Now we find the corresponding $x$ points:
$x_1 = 0.5(-0.57735) + 0.5 = 0.211325$
$x_2 = 0.5(0.57735) + 0.5 = 0.788675$
Step 3: Apply the Quadrature Formula
The formula is $I \approx \frac{b-a}{2}\sum_{i=1}^n w_i f(x_i)$.
$$ I \approx \frac{1-0}{2} [ (1)f(0.211325) + (1)f(0.788675) ] $$
$$ f(0.211325) = \frac{1}{1 + (0.211325)^2} \approx 0.95724 $$
$$ f(0.788675) = \frac{1}{1 + (0.788675)^2} \approx 0.61654 $$
$$ I \approx 0.5 [ 0.95724 + 0.61654 ] = 0.5 [1.57378] \approx 0.78689 $$
Conclusion:
The true value is $\arctan(1) = \pi/4 \approx 0.78540$. Our 2-point Gauss Quadrature result of 0.78689 is remarkably accurate. For comparison, the 3-point Simpson's 1/3 Rule gives an answer of 0.78539, showing that Gauss Quadrature achieved similar accuracy with fewer function evaluations!
No comments
Post a Comment