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.
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.
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\).