Mathematics Source Library
C & ASM


Gauss-Legendre Quadrature

Gauss-Legendre Quadrature

Gauss-Legendre quadrature formulas are used to integrate functions f(x) over a closed and bounded interval [a, b]. Let abf( x ) dx denote the integral of f(x) from a to b. After making the change of variable t = 2(x - a)/(b-a) -1, then

abf( x ) dx = ( (b-a)/2 ) ∫-11f( [(b-a) t + (b + a)] / 2 ) dt.

With respect to the inner product < f,g > = ∫-11 (f(x) g(x) w(x)) dx, the Legendre polynomials P n(x) = 1 / ( 2 nn! ) ( d n / dx n )( x² - 1 ) n for n > 0, and P0(x) = 1 form an orthogonal family of polynomials with weight function w(x) = 1 on the interval [-1,1].

The n-point Gauss-Legendre quadrature formula, GLn ( f(x) ), for approximating the integral of f(x) over [-1,1], is given by
GLn ( f(x) ) = A1 f(x1) + ··· + An f(xn),
where xi , i = 1,...,n, are the zeros of Pn and Ai = 2 ( 1 - xi² ) / [n Pn-1 (xi) ] ², i = 1,...,n.

The truncation error is
-11 f(x) dx - GLn ( f(x) ) = K f (2n)( c ) / ( 2n! ),
where K is a constant, and c is some unknown number -1 < c < 1. The constant K is easily determined from K = -11 ( x 2n ) dx - GLn ( x 2n ).

Generalizing, in order to integrate f(x) over [a,b], the n-point Gauss-Legendre quadrature formula, GLn ( f(x), a, b ), is given by
GLn ( f(x), a, b ) = A'1 f(x'1) + ··· + A'n f(x'n),
where x'i = (b-a) xi /2 + (b+a) / 2 , xi i = 1,...,n, are the zeros of Pn and
A'i = (b-a) ( 1 - xi² ) / [n Pn-1 (xi) ] ² = [ ( b - a ) / 2 ] Ai, i = 1,...,n.

The truncation error is
ab( f(x) ) - GLn ( f(x), a, b ) = K f (2n)( c ) / ( 2n! ),
where K is a constant, and c is some unknown number a < c < b.

Function List

For n = 2,3,4,5,6,7,8,9,10,12,14,16,20,24,28,32,40,48,56,64,82,96, and 100
  • double Gauss_Legendre_Integration_n pts( double a, double b, double (*f)(double) )

    Integrate the user supplied function (*f)(x) from a to b where a is the lower limit of integration, b > a is the upper limit of integration.

  • void Gauss_Legendre_Zeros_n pts( double nodes[ ])

    Returns the zeros of the Legendre polynomial Pn(x) in the user allocated array nodes of dimension n.

  • void Gauss_Legendre_Coefs_n pts( double wght[ ] )

    Returns the weights of the Gauss-Legendre formula in the user allocated array wght of dimension n. The i th element of the array wght is the weight which corresponds to the i th node in the array nodes as returned in Gauss_Legendre_Zeros_n pts( double nodes[ ]).

C Source Code

  • The file, gauss_legendre_2pts.c, contains the versions of Gauss_Legendre_Integration_2pts( ), Gauss_Legendre_Zeros_2pts and Gauss_Legendre_Coefs_2pts( ) written in C.

  • The file, gauss_legendre_3pts.c, contains the versions of Gauss_Legendre_Integration_3pts( ), Gauss_Legendre_Zeros_3pts and Gauss_Legendre_Coefs_3pts( ) written in C.

  • The file, gauss_legendre_4pts.c, contains the versions of Gauss_Legendre_Integration_4pts( ), Gauss_Legendre_Zeros_4pts and Gauss_Legendre_Coefs_4pts( ) written in C.

  • The file, gauss_legendre_5pts.c, contains the versions of Gauss_Legendre_Integration_5pts( ), Gauss_Legendre_Zeros_5pts and Gauss_Legendre_Coefs_5pts( ) written in C.

  • The file, gauss_legendre_6pts.c, contains the versions of Gauss_Legendre_Integration_6pts( ), Gauss_Legendre_Zeros_6pts and Gauss_Legendre_Coefs_6pts( ) written in C.

  • The file, gauss_legendre_7pts.c, contains the versions of Gauss_Legendre_Integration_7pts( ), Gauss_Legendre_Zeros_7pts and Gauss_Legendre_Coefs_7pts( ) written in C.

  • The file, gauss_legendre_8pts.c, contains the versions of Gauss_Legendre_Integration_8pts( ), Gauss_Legendre_Zeros_8pts and Gauss_Legendre_Coefs_8pts( ) written in C.

  • The file, gauss_legendre_9pts.c, contains the versions of Gauss_Legendre_Integration_9pts( ), Gauss_Legendre_Zeros_9pts and Gauss_Legendre_Coefs_9pts( ) written in C.

  • The file, gauss_legendre_10pts.c, contains the versions of Gauss_Legendre_Integration_10pts( ), Gauss_Legendre_Zeros_10pts and Gauss_Legendre_Coefs_10pts( ) written in C.

  • The file, gauss_legendre_12pts.c, contains the versions of Gauss_Legendre_Integration_12pts( ), Gauss_Legendre_Zeros_12pts and Gauss_Legendre_Coefs_12pts( ) written in C.

  • The file, gauss_legendre_14pts.c, contains the versions of Gauss_Legendre_Integration_14pts( ), Gauss_Legendre_Zeros_14pts and Gauss_Legendre_Coefs_14pts( ) written in C.

  • The file, gauss_legendre_16pts.c, contains the versions of Gauss_Legendre_Integration_16pts( ), Gauss_Legendre_Zeros_16pts and Gauss_Legendre_Coefs_16pts( ) written in C.

  • The file, gauss_legendre_20pts.c, contains the versions of Gauss_Legendre_Integration_20pts( ), Gauss_Legendre_Zeros_20pts and Gauss_Legendre_Coefs_20pts( ) written in C.

  • The file, gauss_legendre_24pts.c, contains the versions of Gauss_Legendre_Integration_24pts( ), Gauss_Legendre_Zeros_24pts and Gauss_Legendre_Coefs_24pts( ) written in C.

  • The file, gauss_legendre_28pts.c, contains the versions of Gauss_Legendre_Integration_28pts( ), Gauss_Legendre_Zeros_28pts and Gauss_Legendre_Coefs_28pts( ) written in C.

  • The file, gauss_legendre_32pts.c, contains the versions of Gauss_Legendre_Integration_32pts( ), Gauss_Legendre_Zeros_32pts and Gauss_Legendre_Coefs_32pts( ) written in C.

  • The file, gauss_legendre_40pts.c, contains the versions of Gauss_Legendre_Integration_40pts( ), Gauss_Legendre_Zeros_40pts and Gauss_Legendre_Coefs_40pts( ) written in C.

  • The file, gauss_legendre_48pts.c, contains the versions of Gauss_Legendre_Integration_48pts( ), Gauss_Legendre_Zeros_48pts and Gauss_Legendre_Coefs_48pts( ) written in C.

  • The file, gauss_legendre_56pts.c, contains the versions of Gauss_Legendre_Integration_56pts( ), Gauss_Legendre_Zeros_56pts and Gauss_Legendre_Coefs_56pts( ) written in C.

  • The file, gauss_legendre_64pts.c, contains the versions of Gauss_Legendre_Integration_64pts( ), Gauss_Legendre_Zeros_64pts and Gauss_Legendre_Coefs_64pts( ) written in C.

  • The file, gauss_legendre_82pts.c, contains the versions of Gauss_Legendre_Integration_82pts( ), Gauss_Legendre_Zeros_82pts and Gauss_Legendre_Coefs_82pts( ) written in C.

  • The file, gauss_legendre_96pts.c, contains the versions of Gauss_Legendre_Integration_96pts( ), Gauss_Legendre_Zeros_96pts and Gauss_Legendre_Coefs_96pts( ) written in C.

  • The file, gauss_legendre_100pts.c, contains the versions of Gauss_Legendre_Integration_100pts( ), Gauss_Legendre_Zeros_100pts and Gauss_Legendre_Coefs_100pts( ) written in C.