What is Gauss-Hermite quadrature?
Gauss-Hermite quadrature is a numerical method for approximating integrals over the whole real line that carry the Gaussian weight \(e^{-x^2}\). The n-point rule approximates the integral as a weighted sum of the integrand evaluated at n carefully chosen points: the integral from minus infinity to plus infinity of \(e^{-x^2}\,f(x)\,dx\) is approximately the sum over i of \(w_i\,f(x_i)\). The nodes \(x_i\) are the roots of the physicists' Hermite polynomial \(H_n\), and the weights \(w_i\) are determined by the orthogonality of those polynomials.
$$\int_{-\infty}^{\infty} e^{-x^2} f(x)\,dx \approx \sum_{i=1}^{\text{Order }n} w_i\, f(x_i)$$
How to use the calculator
Pick the order \(n\) (the number of points, from 2 to 100) and the number of display digits, then read off the table of nodes and weights. Because the rebuild uses standard double precision, displayed precision is capped at about 15 significant figures - beyond that, arbitrary-precision arithmetic would be required for the extra digits to be meaningful. The n-point rule integrates every polynomial of degree up to \(2n-1\) exactly.
The formula explained
The nodes are the \(n\) real zeros of \(H_n(x)\), defined by the recurrence \(H_0=1\), \(H_1=2x\), \(H_{k+1}=2x\,H_k - 2k\,H_{k-1}\). The weights are $$w_i = \frac{2^{n-1}\, n!\, \sqrt{\pi}}{n^2\, [H_{n-1}(x_i)]^2}.$$ This calculator uses the stable Golub-Welsch method: it builds the symmetric tridiagonal Jacobi matrix (zero diagonal, off-diagonal \(\sqrt{k/2}\)), finds its eigenvalues (the nodes) and eigenvectors, and sets each weight to \(\sqrt{\pi}\) times the square of the first component of the corresponding normalized eigenvector. This avoids overflow from large factorials.
Worked example (n = 2)
\(H_2(x) = 4x^2 - 2\) has roots \(x = \pm \frac{1}{\sqrt{2}} = \pm 0.7071067811865475\). Each weight is \(\frac{2^1 \cdot 2! \cdot \sqrt{\pi}}{2^2 \cdot [H_1(x_i)]^2}\). With \(H_1(x)=2x\), \([H_1]^2 = 2\), so each weight $$= \frac{2 \cdot 2 \cdot 1.7724538509055160}{4 \cdot 2} = 0.8862269254527580.$$ Their sum is \(\sqrt{\pi} = 1.7724538509055160\), a useful self-check.
How to Apply the Nodes and Weights to an Integral
Gauss-Hermite quadrature approximates integrals over the whole real line that contain the physicists' weight \(e^{-x^2}\):
$$\int_{-\infty}^{\infty} e^{-x^2} f(x)\,dx \approx \sum_{i=1}^{n} w_i\, f(x_i)$$
- Choose n. A larger n integrates higher-degree polynomials exactly, but it only helps if f is smooth.
- Get the nodes and weights. Read \(x_i\) and \(w_i\) for your chosen order from the calculator.
- Identify f(x). Factor \(e^{-x^2}\) out of the integrand. What remains is \(f(x)\).
- Evaluate f at each node: compute \(f(x_1), \dots, f(x_n)\).
- Multiply by the weights: form each product \(w_i f(x_i)\).
- Sum the products to get the approximation.
Example: n = 2
Evaluate \(\int_{-\infty}^{\infty} e^{-x^2} x^2\,dx\). Here \(f(x)=x^2\). The 2-point rule has nodes \(x_{1,2}=\pm 1/\sqrt{2}\approx \pm 0.70710678\) and weights \(w_1=w_2=\sqrt{\pi}/2\approx 0.88622693\).
$$\sum w_i f(x_i) = \frac{\sqrt{\pi}}{2}\left(\tfrac12\right) + \frac{\sqrt{\pi}}{2}\left(\tfrac12\right) = \frac{\sqrt{\pi}}{2} \approx 0.886227$$
This equals the exact value \(\sqrt{\pi}/2\). The result is exact because \(f\) has degree 2, which is at most \(2n-1 = 3\).
Integrals without a Gaussian factor
To integrate a function \(g(x)\) that has no \(e^{-x^2}\) factor, write
$$\int_{-\infty}^{\infty} g(x)\,dx = \int_{-\infty}^{\infty} e^{-x^2}\,\big(g(x)\,e^{x^2}\big)\,dx,$$
so \(f(x)=g(x)\,e^{x^2}\). This works well only if \(g\) decays faster than a Gaussian. Otherwise \(f\) grows rapidly and the rule performs poorly.
Normal expectations
For \(T\sim N(\mu,\sigma^2)\), substitute \(x=(t-\mu)/(\sqrt{2}\,\sigma)\), that is \(t=\mu+\sqrt{2}\,\sigma x\):
$$E[h(T)] = \frac{1}{\sqrt{\pi}} \int_{-\infty}^{\infty} e^{-x^2}\, h(\mu+\sqrt{2}\,\sigma x)\,dx \approx \frac{1}{\sqrt{\pi}} \sum_{i=1}^{n} w_i\, h(\mu+\sqrt{2}\,\sigma x_i)$$
Interpreting the Nodes, Weights and Accuracy
- Symmetry. The nodes are symmetric about zero: if \(x_i\) is a node, so is \(-x_i\), with the same weight. For odd n, zero is itself a node.
- Node range. The largest node grows on the order of \(\sqrt{2n}\) and approaches that rate from below. The nodes cover a wider interval as n increases.
- Weights. All weights are positive and sum to \(\int e^{-x^2}dx=\sqrt{\pi}\approx 1.7724539\). Positive weights make the rule numerically stable. The outer weights are extremely small. For n = 20 the smallest is about \(10^{-13}\), and it keeps shrinking as n grows. A naive computation of these weights can underflow or lose relative accuracy at large n.
- Degree of exactness. An n-point rule is exact for every polynomial \(f\) of degree up to \(2n-1\).
- Error term. For a sufficiently smooth \(f\), the error is
$$E_n = \frac{n!\,\sqrt{\pi}}{2^n\,(2n)!}\, f^{(2n)}(\xi)$$
for some \(\xi\) on the real line. The result depends on the \(2n\)-th derivative of \(f\), so the rule works best when those derivatives stay small.
- Poor cases. Accuracy drops for non-smooth integrands (kinks, jumps, discontinuities) and for integrands that grow faster than polynomially, such as \(e^{x^2}\) or faster. Increasing n does not reliably fix these cases.
- Precision limits. In double precision (about 15–16 significant digits), results at high n are limited by rounding error. This affects the tiny outer weights most, and the relative accuracy of the nodes and weights can degrade. Treat very high orders with caution and compare results at neighbouring values of n.
FAQ
Why do the weights always sum to sqrt(pi)? Setting \(f(x)=1\) gives the integral of \(e^{-x^2}\) over the real line, which equals \(\sqrt{\pi}\); the quadrature reproduces it exactly.
Which Hermite convention is this? The physicists' convention with weight \(e^{-x^2}\). For the probabilists' weight \(e^{-x^2/2}\) the nodes and weights differ by scaling.
Can I integrate a function without the e^(-x^2) factor? Yes - write \(g(x) = e^{x^2}\,f(x)\), so the integral of \(g\) is approximately the sum of \(w_i\,e^{x_i^2}\,g(x_i)\).