Computation of Gauss-Legendre quadrature rule nodes and weights
|
The Gauss-Legendre quadrature formula (sometimes it is called Gauss quadrature) is used to numerically calculate the integral by using the formula
With the help of a change in the variables (which changes both weights wi and nodes xi ), we can get onto the arbitrary interval [a, b], but we'll consider only the simplest case here. If you perform a change of variables, you should take into account that the formula of error term is changed along with the nodes and weights (you can get a new form by changing the variables in the formula).
The Gauss-Legendre quadrature formula for each number of points is completely defined by the set of nodes xi and weights wi . The algorithm finds these numbers.
Algorithm of nodes and weights calculation
The closed form of the nodes and weights is known only for a small n. Generally, we have to find them numerically. The integration nodes for the n points formula are found as a root of the Legendre polynomial of order n. The root search is an iterative process. An initial approximation is selected for each root and then the roots are found by using the Newton method. Therefore, the bigger n was selected, the bigger order the Legendre polynomial has, and more time is required to find a root with the desired accuracy.
The recurrence formula for Legendre polynomials calculation has the following form:



After calculating xi (roots of the Legendre polynomials of n-th order) weights wi are calculated by using the following formula:

Error term
The formula with n points is accurate for the polynomials of order 2n-1 and lower. Error term En is:
![E_n_ = div(power(2,2n+1)power(n!,4),(2n+1)power(2n!,3))power(f,(2n))(ξ) ξ∈[-1,1]](/SMScripts/visualize.php?mode=normal&code=E_n_%20%3D%20div%28power%282%2C2n%2B1%29power%28n%21%2C4%29%2C%282n%2B1%29power%282n%21%2C3%29%29power%28f%2C%282n%29%29%28%26xi%3B%29%20%20%20%26xi%3B%26in%3B%5B-1%2C1%5D)
Subroutine description
The algorithm gets as the input
- n - a required number of nodes.
The algorithm returns:
- x - array of nodes. Its index ranges within 0 and n-1.
- w - array of weighting coefficients. Its index ranges between 0 and n-1.
The source code was designed by using information from the QUADRULE library.
Links- Eric W. Weisstein. "Legendre-Gauss Quadrature." From MathWorld--A Wolfram Web Resource
Report a bug
C#
C# 1.0 source.
gqgenlegendre.csharp.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
C++
C++ source.
gqgenlegendre.cpp.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
ablas.zip - optimized basic linear algebra subroutines with SSE2 support (for C++ sources only)
C++, multiple precision arithmetic
C++ source. MPFR/GMP is used.
GMP source is available from gmplib.org. MPFR source is available from www.mpfr.org.
gqgenlegendre.mpfr.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
mpfr.zip - precompiled Win32 MPFR/GMP binaries
Delphi
Delphi source.
Can be compiled under FPC (in Delphi compatibility mode).
gqgenlegendre.delphi.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
Visual Basic 6
Visual Basic 6 source.
gqgenlegendre.vb6.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
Zonnon beta
Zonnon source.
Zonnon is an experimental language developed at ETH Zurich.
See www.zonnon.ethz.ch for more information.
gqgenlegendre.zonnon.zip - Computation of Gauss-Legendre quadrature rule nodes and weights
|