Interpolation & Numerical Integration
Reconstructing functions from discrete data, computing definite integrals to high precision, and the Fast Fourier Transform: the most important algorithm of the 20th century.
1. Lagrange Interpolation
Given \(n+1\) data points \((x_0, y_0), \ldots, (x_n, y_n)\), the unique polynomial of degree \(\leq n\) passing through all points is:
\(P(x) = \sum_{i=0}^{n} y_i \prod_{j \neq i} \frac{x - x_j}{x_i - x_j}\)
Each Lagrange basis polynomial \(L_i(x)\) equals 1 at \(x_i\) and 0 at all other nodes.
Runge's Phenomenon
High-degree polynomial interpolation on equally-spaced points can oscillate wildly near the edges. For \(f(x) = 1/(1+25x^2)\) on \([-1,1]\), the interpolation error grows as the degree increases! Fix: use Chebyshev nodes\(x_k = \cos(k\pi/n)\) which cluster near the endpoints.
Lagrange Interpolation and Runge's Phenomenon
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
2. Newton's Divided Differences
A more computationally efficient form using divided differences. Unlike Lagrange, adding a new data point requires only one new coefficient (no recomputation):
\(P(x) = f[x_0] + f[x_0,x_1](x-x_0) + f[x_0,x_1,x_2](x-x_0)(x-x_1) + \cdots\)
Newton's Divided Differences
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
3. Cubic Splines
Instead of one high-degree polynomial, use piecewise cubics joined smoothly (\(C^2\)continuity). No Runge phenomenon, local control, and the interpolant minimizes the total bending energy \(\int |u''(x)|^2 dx\).
Cubic Spline Interpolation
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
4. Gaussian Quadrature
The optimal choice of nodes and weights for numerical integration. An \(n\)-point Gauss-Legendre rule integrates polynomials of degree \(\leq 2n-1\) exactly!
\(\int_{-1}^{1} f(x) \, dx \approx \sum_{i=1}^{n} w_i f(x_i)\)
Nodes \(x_i\) are roots of Legendre polynomials. Error: \(O(h^{2n})\) for \(n\)-point rule.
Gaussian Quadrature: Optimal Integration
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
5. Monte Carlo Integration
For high-dimensional integrals, deterministic methods suffer the curse of dimensionality(cost grows as \(N^d\)). Monte Carlo converges as \(O(1/\sqrt{N})\) regardless of dimension.
\(\int_\Omega f(x) \, dx \approx \frac{V(\Omega)}{N} \sum_{i=1}^{N} f(x_i), \quad x_i \sim \text{Uniform}(\Omega)\)
Error: \(O(\sigma / \sqrt{N})\) by the Central Limit Theorem. Dimension-independent!
Monte Carlo Integration: High Dimensions
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
6. The Fast Fourier Transform (FFT)
The Discrete Fourier Transform converts a signal from time/space domain to frequency domain. The naive DFT costs \(O(N^2)\); the FFT (Cooley-Tukey, 1965) achieves \(O(N \log N)\), making spectral analysis practical for large datasets.
\(\hat{f}_k = \sum_{n=0}^{N-1} f_n \, e^{-2\pi i k n / N}\)
DFT: \(O(N^2)\) multiplications. FFT: \(O(N \log N)\) via divide-and-conquer. For \(N = 10^6\): 10ยนยฒ vs \(2 \times 10^7\) -- a 50,000x speedup!
FFT: Signal Analysis and Filtering
PythonClick Run to execute the Python code
Code will be executed with Python 3 on the server
Method Selection Guide
| Task | Best Method | When to Use |
|---|---|---|
| Smooth interpolation | Cubic splines | Default choice, avoids Runge phenomenon |
| Low-D integration | Gaussian quadrature | Smooth integrands, d = 1-3 |
| High-D integration | Monte Carlo | d > 4, irregular domains |
| Spectral analysis | FFT | \(O(N \log N)\), periodic data |
| Adaptive integration | scipy.integrate.quad | Black-box, handles singularities |