# LEGENDRE_EXACTNESS Exactness of Gauss-Legendre Quadrature Rules

LEGENDRE_EXACTNESS is a C program which investigates the polynomial exactness of a Gauss-Legendre quadrature rule for the interval [-1,+1].

This program is actually appropriate for any quadrature rule that estimates integrals on [-1,+1], and which does not including a weighting function w(x) in the integral. This includes:

• Clenshaw-Curtis rules;
• Fejer rules of Type 1 or 2;
• Gauss-Legendre rules;
• Gauss-Lobatto rules (Gauss rule including both endpoints);
• Gauss-Patterson rules;
• Gauss-Radau rules (Gauss rule including one endpoint);
• Newton-Cotes rules, open and closed forms;

Standard Gauss-Legendre quadrature assumes that the integrand we are considering has a form like:

```        Integral ( -1 <= x <= +1 ) f(x) dx
```

A standard Gauss-Legendre quadrature rule is a set of n positive weights w and abscissas x so that

```        Integral ( -1 <= x <= +1 ) f(x) dx
```
may be approximated by
```        Sum ( 1 <= I <= N ) w(i) * f(x(i))
```

For a standard Gauss-Legendre rule, polynomial exactness is defined in terms of the function f(x). That is, we say the rule is exact for polynomials up to degree DEGREE_MAX if, for any polynomial f(x) of that degree or less, the quadrature rule will produce the exact value of

```        Integral ( -1 <= x <= +1 ) f(x) dx
```

The program starts at DEGREE = 0, and then proceeds to DEGREE = 1, 2, and so on up to a maximum degree DEGREE_MAX specified by the user. At each value of DEGREE, the program generates the corresponding monomial term, applies the quadrature rule to it, and determines the quadrature error. The program uses a scaling factor on each monomial so that the exact integral should always be 1; therefore, each reported error can be compared on a fixed scale.

The program is very flexible and interactive. The quadrature rule is defined by three files, to be read at input, and the maximum degree top be checked is specified by the user as well.

Note that the three files that define the quadrature rule are assumed to have related names, of the form

• prefix_x.txt
• prefix_w.txt
• prefix_r.txt
When running the program, the user only enters the common prefix part of the file names, which is enough information for the program to find all three files.

The exactness results are written to an output file with the corresponding name:

• prefix_exact.txt

### Usage:

legendre_exactness prefix degree_max
where
• prefix is the common prefix for the files containing the abscissa, weight and region information of the quadrature rule;
• degree_max is the maximum monomial degree to check. This would normally be a relatively small nonnegative number, such as 5, 10 or 15.

If the arguments are not supplied on the command line, the program will prompt for them.

### Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

### Languages:

LEGENDRE_EXACTNESS is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version.

### Related Data and Programs:

EXACTNESS, a C library which investigates the exactness of quadrature rules that estimate the integral of a function with a density, such as 1, exp(-x) or exp(-x^2), over an interval such as [-1,+1], [0,+oo) or (-oo,+oo).

HERMITE_EXACTNESS, a C program which tests the polynomial exactness of Gauss-Hermite quadrature rules.

LAGUERRE_EXACTNESS, a C program which tests the polynomial exactness of Gauss-Laguerre quadrature rules for integration over [0,+oo) with density function exp(-x).

LEGENDRE_RULE, a C program which generates a Gauss-Legendre quadrature rule on request.

### Reference:

1. Philip Davis, Philip Rabinowitz,
Methods of Numerical Integration,
Second Edition,
Dover, 2007,
ISBN: 0486453391,
LC: QA299.3.D28.

### Examples and Tests:

LEG_O1 is a standard Gauss-Legendre order 1 rule.

LEG_O2 is a standard Gauss-Legendre order 2 rule.

LEG_O4 is a standard Gauss-Legendre order 4 rule.

LEG_O8 is a standard Gauss-Legendre order 8 rule.

LEG_O16 is a standard Gauss-Legendre order 16 rule.

### List of Routines:

• MAIN is the main program for LEGENDRE_EXACTNESS.
• CH_CAP capitalizes a single character.
• CH_EQI is true if two characters are equal, disregarding case.
• CH_TO_DIGIT returns the integer value of a base 10 digit.
• FILE_COLUMN_COUNT counts the columns in the first line of a file.
• FILE_ROW_COUNT counts the number of row records in a file.
• LEGENDRE_INTEGRAL evaluates a monomial Legendre integral.
• MONOMIAL_QUADRATURE_LEGENDRE applies a quadrature rule to a monomial.
• R8_ABS returns the absolute value of an R8.
• R8MAT_DATA_READ reads the data from an R8MAT file.
• R8MAT_HEADER_READ reads the header from an R8MAT file.
• S_LEN_TRIM returns the length of a string to the last nonblank.
• S_TO_I4 reads an I4 from a string.
• S_TO_R8 reads an R8 from a string.
• S_TO_R8VEC reads an R8VEC from a string.
• S_WORD_COUNT counts the number of "words" in a string.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the C source codes.

Last revised on 15 May 2015.