Gauss-Legendre Quadrature
Description
Gauss-Legendre quadrature formulas are used to integrate functions f(x) over a closed and bound interval [a,b]. Let I[a,b] (f(x)) denote the integral of f(x) from a to b. By making a change of variables t = 2(x - a)/(b-a) -1, then I[-1,1] f( [(b-a) t + (b + a)] / 2 ) = I[a,b] (f(x)). With respect to the inner product < f,g > = I[-1,1] (f(x) g(x) w(x)), 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].
 
For integrating f(x) over [-1,1], the n -point Gauss-Legendre quadrature formula, GLn ( f(x) ), 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 I[-1,1] ( f(x) ) - 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 = I[-1,1] ( x 2n ) - GLn ( x 2n ).
 
Generalizing, in order to integrate f(x) over [a,b], the n -point Gauss-Legendre quadrature formula, GLn ( f(x) ), is given by
GLn ( f(x) ) = 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 I[-1,1] ( f(x) ) - GLn ( f(x) ) = K f (2n)( c ) / ( 2n! ),where K is a constant, and c is some unknown number -1 < c < 1.
Function List
Functions: 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