Gaussian Quadrature Calculator (Gauss-Legendre)

Compute definite integrals with Gauss-Legendre quadrature. Tabulated nodes and weights up to n=10, composite form, and comparison with Simpson's 1/3 rule.

Calculation parameters
Scegli il tipo di calcolo.
Sintassi JavaScript. Esempi: Math.exp(-x*x), 1/(1+x*x), Math.log(x). Math è accessibile senza prefisso: exp(-x*x) funziona.
Limite inferiore di integrazione.
Limite superiore di integrazione.
Numero di punti della formula di Gauss-Legendre. Valori supportati: 2, 3, 4, 5, 6, 8, 10. Un Gauss-Legendre n integra esattamente polinomi fino al grado 2n−1.
Solo per composito: divide [a,b] in M parti e applica Gauss-Legendre n-punti in ciascuna.
Was this calculator useful?

What Gaussian quadrature is

Gaussian quadrature is a family of numerical-integration methods that approximate a definite integral as a weighted sum of function values at a minimal set of optimally chosen points:

∫ab f(x) dx ≈ ((b−a)/2) · ∑i=1n wi · f(((b−a)/2)·xi + (b+a)/2)

where xi are the nodes and wi the weights, chosen so that the formula is exact for polynomials up to degree 2n−1. This is the key advantage over Newton-Cotes rules (trapezoidal, Simpson), which with the same n+1 nodes achieve at best degree n or n+1.

Gauss-Legendre nodes and weights

The calculator uses Gauss-Legendre, which applies to any integral on [a,b] after the change of variables x = ((b−a)/2)·t + (b+a)/2 mapping to [−1,1]. The nodes xi are the roots of the Legendre polynomial Pn(x), and the weights are:

wi = 2 / [(1−xi²)·(Pn′(xi))²]

Values are tabulated for n = 2, 3, 4, 5, 6, 8, 10 to 16-digit precision (standard Abramowitz-Stegun and Numerical Recipes values).

The four modes

  1. Gauss-Legendre on [a, b]: integrates f(x) with the n-point rule, showing transformed nodes, effective weights and f values.
  2. Composite: splits [a, b] into M equal subintervals and applies n-point Gauss-Legendre in each; efficient for non-smooth functions.
  3. Gauss vs Simpson comparison: computes both and reports |IGauss − ISimpson| as a truncation-error estimate.
  4. Nodes & weights table: lists official values on [−1, 1] for the chosen n, useful for manual implementation or teaching.

Why it is so accurate

Gauss's 1814 insight was to abandon equispaced nodes and let 2n parameters (n nodes + n weights) be chosen freely. Imposing 2n conditions makes the rule exact on 2n monomials (1, x, …, x2n−1), hence degree of precision 2n−1.

Example: with n = 5, Gauss-Legendre is exact for polynomials up to degree 9. Simpson's rule on the same 5 equispaced points is exact only up to degree 3. For smooth functions, Gaussian quadrature converges exponentially in n, while Simpson converges algebraically as O(h⁴).

Applications

  • Finite-element methods: stiffness matrices and load vectors on reference elements. All major codes (ANSYS, Abaqus, COMSOL, FEniCS) use Gauss-Legendre.
  • Computational physics: radial integrals in spherical-symmetry problems, atomic Hamiltonians.
  • Quantitative finance: option pricing under stochastic-volatility models; characteristic-function integration.
  • Adaptive quadrature: Gauss-Kronrod (QUADPACK, SciPy quad) adds nodes to Gauss-Legendre to estimate error.
  • Machine learning: posterior-likelihood integration in variational Bayesian methods.

Limits and caveats

  • For singular integrands (like 1/√x at 0), use a regularising change of variables or weighted quadratures (Gauss-Chebyshev, Gauss-Jacobi).
  • For improper integrals on infinite intervals, use Gauss-Hermite (weight e−x²) or Gauss-Laguerre (weight e−x).
  • For high-frequency oscillatory integrands, many nodes are needed; Filon or Levin integration is more efficient.
  • For discontinuous functions, Gauss-Legendre loses exponential convergence; adaptive Simpson or domain partitioning is better.

History of Gaussian quadrature

The method was introduced by Carl Friedrich Gauss in 1814: he asked what the optimal choice of evaluation points would be to maximise the accuracy of a numerical integration formula. The answer was surprising: choosing as nodes the roots of the Legendre polynomials and suitable weights, an n-point formula integrates exactly all polynomials up to degree 2n−1, twice what equally spaced nodes would give. Later Carl Gustav Jacobi provided a more elegant proof and generalised the method to other families of orthogonal polynomials. Today Gaussian quadrature is one of the pillars of numerical analysis and scientific computing, from finite element methods to computational physics.

Variants of Gaussian quadrature

The Gauss-Legendre method is only the best known of a family. By changing the weight function in the integral, variants suited to different problems arise: Gauss-Chebyshev quadrature uses the weight 1/√(1−x²), useful for integrands with singularities at the endpoints; Gauss-Hermite integrates over the whole real line with weight e^(−x²), fundamental in quantum mechanics and probability; Gauss-Laguerre integrates over [0, ∞) with weight e^(−x), typical of decay problems and transforms. All share the same principle: nodes as roots of orthogonal polynomials and degree of precision 2n−1, adapted to the domain and the nature of the integrand.

Updated July 2026

Frequently Asked Questions

Why is Gauss-Legendre more accurate than Simpson with the same points?

Because it optimises both the weights and the node positions, whereas Simpson uses fixed equally spaced nodes. With n well-chosen nodes, the Gaussian formula integrates exactly polynomials up to degree 2n−1, against about degree n−1 for fixed-node formulas. This doubling of the degree of precision makes Gauss-Legendre far more accurate for the same computational cost, especially with smooth integrands.

What are Legendre polynomials?

They are a family of orthogonal polynomials on the interval [−1, 1] with respect to the unit weight, denoted Pₙ(x). Their roots give the optimal nodes of Gaussian quadrature. They satisfy a three-term recurrence relation and appear in physics in the solution of Laplace's equation in spherical coordinates. Their orthogonality is what guarantees the method's degree of precision of 2n−1.

Why transform to [−1, 1]?

Because the Gauss-Legendre nodes and weights are tabulated once and for all on the standard interval [−1, 1]. To integrate over a general interval [a, b] one applies the linear transformation x = ((b−a)/2)·t + (a+b)/2, which maps t from [−1, 1] to [a, b], multiplying the result by the factor (b−a)/2. Thus a single table of nodes serves any interval of integration.

How many nodes for a good approximation?

It depends on the regularity of the integrand. For smooth functions (polynomials, exponentials, trigonometric) a few nodes suffice: even 5 or 6 points reach very high precision. For functions with rapid oscillations, corners or near-singularities, more nodes are needed, or better, the composite version that subdivides the interval. Adding nodes on a smooth integrand makes the error converge extremely fast.

What is Gauss-Kronrod quadrature?

It is an extension of Gaussian quadrature that adds nodes to an existing formula to obtain, with few extra evaluations, a second estimate of the integral. The difference between the two estimates gives an error estimate, enabling adaptive integration that refines the nodes only where needed. It is the method behind automatic integration routines such as QUADPACK, used in many scientific libraries.

Does it handle improper integrals?

Classic Gauss-Legendre requires a finite interval and a bounded integrand. For integrals over infinite domains or with integrands that diverge at the endpoints, the variants are preferable: Gauss-Laguerre for [0, ∞), Gauss-Hermite for the whole real line, Gauss-Chebyshev for endpoint singularities. Alternatively, one applies a change of variable that turns the improper integral into a proper one before using Gauss-Legendre.

Can I compute multidimensional integrals?

Yes, by applying the product formula: the Gaussian rules along each dimension are combined. The cost, however, grows exponentially with dimension (nᵈ evaluations in d dimensions), the so-called curse of dimensionality. For integrals in many dimensions, Monte Carlo methods or sparse rules (Smolyak grids) are therefore preferred, limiting the number of points while keeping good accuracy.

What variants of Gaussian quadrature exist?

Besides Gauss-Legendre there are variants that change the weight function: Gauss-Chebyshev with weight 1/√(1−x²) for endpoint singularities, Gauss-Hermite with weight e^(−x²) on the real line (used in probability and quantum mechanics), Gauss-Laguerre with weight e^(−x) on [0, ∞) for decay problems, and Gauss-Jacobi for more general weights. All use roots of orthogonal polynomials and have degree of precision 2n−1.

Comments (0)

No comments yet. Be the first!