Calculating an Integral Using Gauss-Legendre Quadrature

Purpose
The purpose of this experiment is to calculate the area under a curve using Gauss-Legendre quadrature.

Materials and Equipment

Software Requirements
Windows 95
Delphi 3 or 4 (to recompile)

Hardware Requirements
VGA display

Procedure

1. If desired, change the possible Integrand functions that are selectable in the ComboBoxFunction ComboBox. Be sure to modify the TFormQuadrature.ComboBoxFunctionChange procedure.
2. Compile the GaussLegendreTest project in Delphi 3 or 4.
3. Run the GaussLegendreTest program.
4. Experiment with various Integrand functions and definite integral limits.

Discussion
The following data were taken using the GaussLegendreTest program using 15-point quadrature:

 Integrand A B Observed Value Exact Value 1/x 1.0 2.0 0.69314 71806 27782 0.69314 71805 59945 exp(x) 0.0 1.0 1.71828 18286 2713 1.71828 18284 59045 = e - 1 sin(x) 0.0 3.141593 2.00000 00002 5578 2

This technique of integrand evaluation at n+1 functional values should yield the exact integral when the Integrand is a polynomial of degree 2n+1 or less. This is because of the use of orthogonal Legendre polynomials.

A function can be passed as a parameter using a construct like the following:

TYPE TRealFunction = FUNCTION(CONST X: DOUBLE): DOUBLE;

FUNCTION GaussLegendreQuadrature(CONST A, B: DOUBLE; CONST N: INTEGER; CONST F: TRealFunction): DOUBLE;

The function "F" is passed to GaussLegendreQuadrature as the integrand of the definite integral evaluated from A to B.

For a commerical package, take a look at Quadrature by Engineering Objects International.

Conclusions
Gauss-Lengendre is an efficient technique for numeric evaluation of definite integrals. The use of 15-point quadrature can result in area calculations that are accurate to about 10 significant digits for some integrands.

Keywords
quadrature, numeric integration, Gauss-Legendre, function parameter

Files
Delphi 3/4 Source (6 KB): GaussLegendre.ZIP

References

Eric Weisstein's World of Mathematics
http://mathworld.wolfram.com/topics/NumericalIntegration.html

Updated 18 Feb 2002

since 1 Nov 1998