Gaussian Integration Is Cool

Gaussian integration is cool
Numerical integration techniques are often used in a variety of domains where exact solutions are not available. In this blog, we'll look at a numerical integration technique called gaussian quadrature, specifically chebyshev-gauss quadrature. This is applicable for evaluating definite integrals over
Gaussian quadrature #
At it's core, gaussian quadrature gives us a way to evaluate a definite integral of a function by using the function evaluations at special points called nodes, the exact location of which can vary depending on the technique used - we'll look at a specific example using chebyshev nodes later on. Here's the basic idea for a definite integral over
Elementary integration techniques work by approximating the function
This is a great improvement in terms of numerical accuracy for the accuracy you get per function evaluation at a node. Gaussian quadrature does this by carefully selecting nodes - the nodes are given by the roots of an orthogonal polynomial function. These orthogonal polynomials act as a "basis", just like spline coefficients do for spline fitting (with the difference of global instead of local support). By the definition of orthogonality, these have an inner product (dot product in euclidean space) of zero with each other, and that simplifies the necessary calculations (proof)[1] .
Chebyshev-Gauss quadrature #
This flavour of gaussian quadrature involves using the roots of chebyshev polynomials to decide which nodes to evaluate the function for integration at. The roots of this polynomial are concentrated more on the edges of the domain helping counter oscillation at the boundaries when fitting polynomials (Runge's phenomenon). Additionally, the weights w are fixed at
This specific form of gaussian quadrature can integrate functions of this form:
where the nodes
Let's extend this to arbitrary intervals and functional forms.
Extending to general functions and integration intervals #
Basically, our goal is to make Chebyshev-Gauss quadrature it work for the following integral:
Note that we don't have
Let's see it in action! #
This is my first time trying a marimo notebook. It reminds me of what pluto is for julia - in the sense it's a reactive notebook, but with a lot of other cool features. The result is a highly interactive, embeddable notebook experience that's great for short blogs like this - and runs in the browser with WASM! I've also made the code available as a gist here.
You can play around with the slider which controls the number of nodes used for integration. Changing it effects all other conencted cells, allowing you to compare the accuracy of the two integral approximation techniques. For this example, we integrate
Parting thoughts #
This is a cool numerical integration technique I thought I'd share. I used it in my library for estimating rates of sea level change - check out EIV_IGP_jax. A gaussian process prior is fit with MCMC on the rate of sea level change, which is then compared to the observation (heights and times) of sea level proxies by integrating the rate process. The integration step uses chebyshev-gauss quadrature. The specific implementation of the quadrature in that project makes heavy use of broadcasting operations for efficient vectorisation of these calculations over a grid. That was a fun project too, and maybe can be a blog for another day.
The proof linked to stackoverflow is for when legendre polynomials are used to compute node locations (Gauss-Legendre integration). The proof is largely unchanged for Chebyshev-Gauss integration with a notable difference that the "weight function" (multiplied inside the integral) in the latter case is
1 / ( 1 − x 2 ) 1/(\sqrt{1-x^2}) 1/(√1−x2), and1 1 1 for the prior case. This is why the functional form requirement for chebyshev-gauss has that term, as seen in the next section. The use of "weight function" inside the integral and "weight" in the summation term is confusing, I'll agree. This is why introductions to the chebyshev-gauss quadrature directly introduce it as a functional form requirement, as I've done here. ↩︎
- Previous: SDFs and Fast sweeping in JAX
What's Your Reaction?






