Gauss-Legendre Quadrature Nodes and Weights Calculator

Gauss-Legendre Quadrature Nodes and Weights Calculator

Emerging AI Skill PRO

Enter Calculation

Formula

∫−11f(x)dx≈∑i=1nwif(xi)where{n=Order nxi:Pn(xi)=0wi=2(1−xi2)[Pn′(xi)]2\begin{gathered} \int_{-1}^{1} f(x)\,dx \approx \sum_{i=1}^{n} w_i\, f(x_i) \\[1.5em] \text{where}\quad \left\{ \begin{aligned} n &= \text{Order n} \\ x_i &: P_n(x_i) = 0 \\ w_i &= \frac{2}{\left(1 - x_i^{2}\right)\left[P_n^{\prime}(x_i)\right]^{2}} \end{aligned} \right. \end{gathered}
Usage stats

Advertisement

Results

20-Point Gauss-Legendre Rule on [-1, 1]
2
sum of weights (should equal 2)
i Node x_i Weight w_i
1 -0.993128599185095 0.017614007139152
2 -0.963971927277914 0.040601429800387
3 -0.912234428251326 0.062672048334109
4 -0.839116971822219 0.083276741576705
5 -0.746331906460151 0.10193011981724
6 -0.636053680726515 0.118194531961518
7 -0.510867001950827 0.131688638449176
8 -0.37370608871542 0.142096109318382
9 -0.227785851141645 0.149172986472604
10 -0.076526521133497 0.152753387130726
11 0.076526521133497 0.152753387130726
12 0.227785851141645 0.149172986472604
13 0.37370608871542 0.142096109318382
14 0.510867001950827 0.131688638449176
15 0.636053680726515 0.118194531961518
16 0.746331906460151 0.10193011981724
17 0.839116971822219 0.083276741576705
18 0.912234428251326 0.062672048334109
19 0.963971927277914 0.040601429800387
20 0.993128599185095 0.017614007139152

Report an error on this page

What is the Gauss-Legendre Quadrature Calculator?

This tool computes the nodes (abscissas) and weights of the n-point Gauss-Legendre quadrature rule on the reference interval [-1, 1]. Gauss-Legendre quadrature is a numerical integration method that approximates a definite integral as a weighted sum of function values: the integral of \(f(x)\) from \(-1\) to \(1\) is approximately the sum over \(i\) of \(w_i\) times \(f(x_i)\). With just \(n\) points it integrates any polynomial up to degree \(2n-1\) exactly, making it far more accurate than equally-spaced rules like the trapezoidal or Simpson methods.

How to Use It

Pick the order \(n\) (the number of points, 2 to 100) and optionally the number of significant digits to display. The calculator returns a table of \(n\) rows, each with a node \(x_i\) and its weight \(w_i\). The nodes are symmetric about 0 and all lie strictly inside \((-1, 1)\); the weights are all positive and sum to exactly 2, the length of the interval. To integrate over an arbitrary interval \([a, b]\), map each node with \(t_i = \frac{b-a}{2} x_i + \frac{a+b}{2}\) and multiply each weight by \(\frac{b-a}{2}\).

The Formula Explained

The nodes are the \(n\) roots of the Legendre polynomial \(P_n(x)\), built with Bonnet's recurrence: \(P_0=1\), \(P_1=x\), and \(P_k = \frac{(2k-1) x P_{k-1} - (k-1) P_{k-2}}{k}\). Each weight is $$w_i = \frac{2}{\left(1 - x_i^{2}\right)\left[P_n^{\prime}(x_i)\right]^{2}},$$ where the derivative is \(P_n^{\prime}(x) = \frac{n\left(x P_n(x) - P_{n-1}(x)\right)}{x^2 - 1}\). Roots are found by Newton's method seeded at \(x = \cos\left(\frac{\pi (i - 0.25)}{n + 0.5}\right)\), which converges in a few iterations.

Advertisement
Smooth function over [-1,1] sampled at several non-uniform symmetric nodes with weighted contributions
Gauss-Legendre quadrature approximates the integral as a weighted sum of function values at specially chosen nodes.

Worked Example (n = 3)

The roots of \(P_3\) are \(x = 0\) and \(x = \pm\sqrt{3/5} = \pm 0.7745966692\). The weight at \(x = 0\) is \(\frac{8}{9} = 0.888888889\), and the weight at each \(x = \pm 0.7745966692\) is \(\frac{5}{9} = 0.555555556\). The weights sum to $$\frac{5}{9} + \frac{8}{9} + \frac{5}{9} = 2,$$ and this 3-point rule integrates polynomials up to degree 5 exactly.

Three symmetric Gauss-Legendre nodes on [-1,1] with the central node carrying a larger weight
The 3-point rule uses a central node and two symmetric outer nodes, with the central node given the largest weight.

Applying the Rule to a Definite Integral Step by Step

The calculator returns nodes \(x_i\) and weights \(w_i\) on the standard interval \([-1,1]\). To integrate over a general interval \([a,b]\), follow these steps.

  1. Choose n. Pick the order (2 to 100) in the calculator. An n-point rule integrates every polynomial of degree up to \(2n-1\) exactly. Smooth integrands usually need only a small n.
  2. Get \(x_i\) and \(w_i\). Read the nodes and weights for that n. The nodes are the roots of the Legendre polynomial \(P_n\), and the weights satisfy \(w_i = \dfrac{2}{(1-x_i^2)\,[P_n'(x_i)]^2}\).
  3. Map the nodes to \([a,b]\). $$t_i = \frac{b-a}{2}\,x_i + \frac{a+b}{2}$$
  4. Scale the weights. $$w_i' = \frac{b-a}{2}\,w_i$$ The factor \(\frac{b-a}{2}\) is the Jacobian of the change of variable.
  5. Evaluate the function at each mapped node: \(f(t_i)\).
  6. Sum. $$\int_a^b f(t)\,dt \approx \sum_{i=1}^{n} w_i'\, f(t_i)$$

Check 1: \(x^2\) on \([-1,1]\) with n = 2

For n = 2 the nodes are \(x_{1,2} = \mp 1/\sqrt{3} \approx \mp 0.5773503\) and both weights equal 1. Then $$\sum w_i x_i^2 = 1\cdot\tfrac13 + 1\cdot\tfrac13 = \tfrac23,$$ which equals the exact value \(\int_{-1}^{1} x^2\,dx = 2/3\). This is expected, because degree 2 is at most \(2n-1 = 3\).

Check 2: \(e^x\) on \([0,1]\) with n = 2

Here \(a=0\) and \(b=1\), so \(t_i = 0.5\,x_i + 0.5\), which gives \(t_1 \approx 0.2113249\) and \(t_2 \approx 0.7886751\). The scaled weights are \(w_i' = 0.5\cdot 1 = 0.5\).

$$\int_0^1 e^x\,dx \approx 0.5\,(e^{0.2113249} + e^{0.7886751}) \approx 0.5\,(1.235313 + 2.200479) \approx 1.71790$$

The exact value is \(e - 1 \approx 1.71828\), so the error is about \(4\times 10^{-4}\) with just two function evaluations. Increasing n shrinks the error very quickly.

Advertisement

Interpreting the Nodes and Weights

  • Symmetry. The nodes are symmetric about 0: \(x_i = -x_{n+1-i}\). The matching weights are equal: \(w_i = w_{n+1-i}\). For odd n, the middle node is exactly 0.
  • Positive weights that sum to 2. Every weight is strictly positive, and \(\sum w_i = 2\), the length of \([-1,1]\), since the rule integrates the constant 1 exactly. Positive weights make the rule numerically stable, with no cancellation between large terms of opposite sign. After scaling to \([a,b]\), the weights sum to \(b-a\).
  • Node locations. All nodes lie strictly inside \((-1,1)\), and the endpoints are never used. As n grows, the nodes cluster toward the endpoints. Their density follows roughly \(1/\sqrt{1-x^2}\), and the weights near the ends become small.
  • Degree of exactness. An n-point rule is exact for all polynomials of degree \(\le 2n-1\). This is the maximum possible for n nodes, twice what equally spaced Newton-Cotes rules with n points typically achieve.
  • Error term. On \([-1,1]\) the error is $$E_n = \frac{2^{2n+1}\,(n!)^4}{(2n+1)\,[(2n)!]^3}\; f^{(2n)}(\xi), \qquad \xi \in (-1,1).$$ For n = 2 the coefficient is \(1/135\). On \([a,b]\) the error is multiplied by \(\left(\frac{b-a}{2}\right)^{2n+1}\). The error is therefore governed by the size of the \(2n\)-th derivative.
  • Smooth integrands. For analytic functions such as \(e^x\), \(\sin x\) or rational functions with poles far from the interval, convergence is geometric (exponentially fast in n). A modest n often reaches near machine precision.
  • Singular or non-smooth integrands. If f has a kink, a jump, an endpoint singularity (such as \(\sqrt{x}\) or \(\ln x\) at 0), or a nearby pole, the high derivatives are large or undefined. Convergence then drops to algebraic and may be slow. Practical remedies are to split the interval at the trouble point, apply a variable substitution that removes the singularity, use a rule with a matching weight function (such as Gauss-Jacobi or Gauss-Chebyshev), or use composite or adaptive Gauss rules.
  • High orders. Very large n gives no benefit if f is not smooth. Compare results for two different n to estimate the error.

FAQ

Why do the weights sum to 2? Integrating the constant function \(f(x) = 1\) over \([-1, 1]\) gives 2, and quadrature must reproduce constants exactly, so the weights must total the interval length.

How accurate are the values? This is a double-precision rebuild giving about 15 significant digits. Display options requesting more digits are rounded to what double precision can represent.

What is the maximum degree integrated exactly? An \(n\)-point rule is exact for all polynomials of degree up to \(2n-1\).

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators