What this calculator does
This tool computes the nodes (abscissae \(x_i\)) and weights \(w_i\) for the classical Gaussian quadrature rules. With these you approximate a weighted integral as a finite weighted sum, integrating polynomials up to degree \(2n-1\) exactly for the standard Gauss rules. Supported rules: Gauss-Legendre, Chebyshev of the first and second kind, generalized Laguerre, Hermite, Jacobi, and Gauss-Lobatto.
$$\int_{-1}^{1} f(x)\,dx \approx \sum_{i=1}^{\text{n}} w_i\, f(x_i), \qquad \text{Gauss-Legendre}$$How to use it
Pick a rule under "Kinds", choose the order \(n\) (number of nodes, 2 to 100), and for Laguerre or Jacobi supply the exponent parameters Alpha and Beta (each must be greater than \(-1\)). The result lists each node and its weight, plus the sum of weights, which should equal the 0th moment of the weight function (for Legendre that is 2, for Hermite it is the square root of pi).
The formula explained
For a family of orthogonal polynomials with three-term recurrence, the nodes are the roots of the degree-\(n\) polynomial and the weights come from the eigenvectors of the symmetric tridiagonal Jacobi matrix \(J\) (the Golub-Welsch method): \(w_i = \mu_0 (v_{1,i})^2\). Chebyshev rules use exact trigonometric closed forms, Legendre and Lobatto use Newton iteration on the Legendre polynomial, and Laguerre, Hermite and Jacobi use the Jacobi-matrix eigensolver.
$$w_i = \frac{2}{\left(1-x_i^2\right)\left[P_{\text{n}}^{\prime}(x_i)\right]^2}$$
Worked example
Gauss-Legendre with \(n = 2\): nodes are plus and minus \(1/\sqrt{3} = 0.5773502692\), and both weights equal 1, so the sum of weights is 2. Check: the integral of \(x^2\) over \([-1, 1]\) is \(2/3\), and the rule gives $$1\cdot\left(\tfrac{1}{3}\right) + 1\cdot\left(\tfrac{1}{3}\right) = \tfrac{2}{3}.$$
How to Apply the Nodes and Weights to an Integral
- Choose the rule that matches the weight function. If the integrand has the form \(w(x)\,f(x)\) with \(w(x)\) from the table above, use that rule and integrate only the smooth part \(f(x)\). For a plain integral with no weight, Gauss-Legendre is the usual choice.
- Select the order \(n\). Start small (for example 3 to 5) for smooth functions.
- Get the nodes \(x_i\) and weights \(w_i\) from the calculator (set the rule type, \(n\), and \(\alpha\), \(\beta\) where they apply).
- Map to a general interval \([a,b]\) (Legendre, Lobatto): use $$x=\frac{b-a}{2}\,t+\frac{a+b}{2}$$ where \(t_i\) are the tabulated nodes on \([-1,1]\). Then $$\int_a^b f(x)\,dx\approx\frac{b-a}{2}\sum_{i=1}^{n} w_i\, f(x_i).$$ The factor \((b-a)/2\) is the Jacobian of the substitution.
- Evaluate \(f\) at each mapped node.
- Compute the sum \(\sum w_i f(x_i)\) and multiply by the scale factor if you mapped the interval.
- Check the weights. They must add up to the 0th moment of the weight function (for example 2 for Legendre, \(\pi\) for Chebyshev 1st kind, \(\sqrt{\pi}\) for Hermite). A mismatch signals a wrong rule or parameter.
- Test convergence. Repeat with a larger \(n\). If the result stops changing to the digits you need, accept it. Note that Gauss rules with different \(n\) generally do not share nodes, so you cannot reuse earlier evaluations.
Quick example. Gauss-Legendre with \(n=2\) has nodes \(\pm 1/\sqrt{3}\) and weights \(1,1\). For \(f(x)=x^2\) on \([-1,1]\): $$1\cdot\tfrac13+1\cdot\tfrac13=\tfrac23,$$ which equals the exact integral \(\int_{-1}^{1}x^2\,dx=2/3\), as expected since the degree 2 is at most \(2n-1=3\).
Error term. For Gauss-Legendre on \([-1,1]\) the error is $$E_n=\frac{2^{2n+1}(n!)^4}{(2n+1)\,[(2n)!]^3}\,f^{(2n)}(\xi)$$ for some \(\xi\in(-1,1)\). The rule is exact for polynomials up to degree \(2n-1\), and the error depends on the size of the \(2n\)-th derivative, so smooth (analytic) integrands converge very fast while integrands with singularities or kinks converge slowly.
Glossary of Terms
- Node (abscissa)
- A point \(x_i\) at which the integrand is evaluated. For Gauss rules the nodes are the roots of the degree-\(n\) orthogonal polynomial for the chosen weight function.
- Weight
- The coefficient \(w_i\) multiplying \(f(x_i)\) in the quadrature sum.
- Order \(n\)
- The number of nodes (and weights) in the rule.
- Degree of exactness
- The highest polynomial degree integrated exactly. It is \(2n-1\) for Gauss rules and \(2n-3\) for Gauss-Lobatto, because two nodes are fixed at the endpoints.
- Weight function
- The non-negative function \(w(x)\) that defines the inner product \(\int w(x)\,p(x)\,q(x)\,dx\) and hence the family of orthogonal polynomials.
- Orthogonal polynomials
- A sequence of polynomials \(p_k\) with \(\int w\,p_j\,p_k\,dx=0\) for \(j\ne k\), such as Legendre, Chebyshev, Laguerre, Hermite and Jacobi polynomials.
- Three-term recurrence
- The relation \(p_{k+1}(x)=(x-a_k)\,p_k(x)-b_k\,p_{k-1}(x)\) satisfied by orthogonal polynomials; its coefficients define the quadrature rule.
- Jacobi matrix
- The symmetric tridiagonal matrix built from the recurrence coefficients (diagonal \(a_k\), off-diagonal \(\sqrt{b_k}\)). Its eigenvalues are the nodes.
- Golub-Welsch algorithm
- A method that computes the nodes as eigenvalues of the Jacobi matrix and the weights from the first components of the normalized eigenvectors: \(w_i=\mu_0\,v_{i,1}^2\).
- 0th moment
- \(\mu_0=\int w(x)\,dx\) over the interval. The weights must sum to this value.
- Alpha and Beta parameters
- Shape parameters of the weight function. Laguerre uses \(\alpha\) in \(x^{\alpha}e^{-x}\); Jacobi uses both in \((1-x)^{\alpha}(1+x)^{\beta}\). Both must be greater than \(-1\) for the weight to be integrable.
FAQ
Why should weights be positive? For classical Gauss rules all weights are strictly positive; a negative weight signals numerical error.
What does the sum of weights mean? It equals the integral of the weight function over the interval (the 0th moment). For Hermite, \(e^{-x^2}\) integrates to \(\sqrt{\pi}\) over the whole line.
Why must Alpha and Beta exceed -1? Otherwise the weight function is not integrable and the moments diverge, so no valid rule exists.