# QUADRATURE_LEAST_SQUARES Least Squares Quadrature Rules

QUADRATURE_LEAST_SQUARES is a MATLAB library which computes weights for "sub-interpolatory" quadrature rules.

A large class of quadrature rules may be computed by specifying a set of N abscissas, or sample points, X(1:N), determining the Lagrange interpolation basis functions L(1:N), and then setting a weight vector W by

```        W(i) = I(L(i))
```
after which, the integral of any function f(x) is estimated by
```        I(f) \approx Q(f) = sum ( 1 <= i <= N ) W(i) * f(X(i))
```

We call this an interpolatory rule because the function f(x) has first been interpolated by

```        f(x) \approx sum ( 1 <= i <= N ) L(i) * f(X(i))
```
after which, we apply the integration operator:
```        I(f) \approx I(sum ( 1 <= i <= N )   L(i)  * f(X(i)))
=         sum ( 1 <= i <= N ) I(L(i)) * f(X(i))
=         sum ( 1 <= i <= N )   W(i)  * f(X(i)).
```

For badly chosen sets of X, or high values of N, or unruly functions f(x), interpolation may be a bad way to approximate the function. An alternative is to seek a polynomial interpolant of degree D < N-1, and then integrate that. We might call this a "sub-interpolatory" rule.

As it turns out, a natural way to seek such a rule is to write out the N by D+1 Vandermonde matrix and use a least squares solver. Even though the N by N Vandermonde matrix is ill-conditioned for Gauss elimination, a least squares approach can produce usable solutions from the N by D+1 matrix.

The outline of this procedure was devised by Professor Mac Hyman of Tulane University.

### Licensing:

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

### Languages:

QUADRATURE_LEAST_SQUARES 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:

CLENSHAW_CURTIS_RULE, a MATLAB library which defines a multiple dimension Clenshaw Curtis quadrature rule.

QUADMOM, a MATLAB library which computes a Gaussian quadrature rule for a weight function rho(x) based on the Golub-Welsch procedure that only requires knowledge of the moments of rho(x).

QUADRATURE_GOLUB_WELSCH, a MATLAB library which computes the points and weights of a Gaussian quadrature rule using the Golub-Welsch procedure, assuming that the points have been specified.

QUADRATURE_WEIGHTS_VANDERMONDE, a MATLAB library which computes the weights of a quadrature rule using the Vandermonde matrix, assuming that the points have been specified.

QUADRULE, a MATLAB library which defines quadrature rules for approximating an integral over a 1D domain.

QUADRULE_FAST, a MATLAB library which defines efficient versions of a few 1D quadrature rules.

TEST_INT, a MATLAB library which defines test integrands for 1D quadrature rules.

TRUNCATED_NORMAL_RULE, a MATLAB program which computes a quadrature rule for a normal probability density function (PDF), also called a Gaussian distribution, that has been truncated to [A,+oo), (-oo,B] or [A,B].

VANDERMONDE, a MATLAB library which carries out certain operations associated with the Vandermonde matrix.

### Source Code:

• ncc_set.m, sets abscissas and weights for Newton-Cotes Closed quadrature.
• r8vec_uniform_ab.m, returns a pseudorandom R8VEC in [A,B].
• timestamp.m, prints the current YMDHMS date as a time stamp.
• weight_ls.m, computes the weights for a quadrature rule, based on N points, and a least squares polynomial approximant of degree D.

### Examples and Tests:

• qls_test.m, calls all the tests;
• qls_test_output.txt, the output from a rule of all the tests;
• qls_test01.m, uses weight_ls() to compute quadrature rules that are comparable to Newton-Cotes rules on [-1,+1].
• qls_test02.m, compares Monte Carlo and least squares estimates for the Runge function in [-5,+5].

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

Last revised on 11 March 2014.