Contents
ALGORITHMS
Site map
Links
Site and author
News
About the site
FAQ
Contact
TERMS OF USE
Contents - Numerical integration - Gaussian quadratures - Computation of Gauss-Legendre quadrature rule nodes and weights

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 integral(f(x)dx,-1,1) by using the formula integral(f(x)dx,-1,1) = sum(w_i_f(x_i_),i=0,n-1)+E_n_

With the help of a change in the variables (which changes both weights w and nodes x), 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 x and weights w. 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:

P_-1_ = 0

P_0_ = 1

(j+1)P_j+1_ = (2j+1)xP_j_-jP_j-1_

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


w_i_ = div(2,(1-index(x,i,2))power(div(d,dx)p_i_(x_i_),2))

Error term

The formula with n points is accurate for the polynomials of order 2n-1 and lower. Error term E is:


E_n_ = div(power(2,2n+1)power(n!,4),(2n+1)power(2n!,3))power(f,(2n))(ξ)   ξ∈[-1,1]

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

  1. Eric W. Weisstein. "Legendre-Gauss Quadrature." From MathWorld--A Wolfram Web Resource

Report a bug

Source codes

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



 
 
Sergey Bochkanov, Vladimir Bystritsky
Copyright © 1999-2008