# NAG Library Function Document

## 1Purpose

Given the $2n+l$ moments of the weight function, nag_quad_1d_gauss_recm (d01tec) generates the recursion coefficients needed by nag_quad_1d_gauss_wrec (d01tdc) to calculate a Gaussian quadrature rule.

## 2Specification

 #include #include
 void nag_quad_1d_gauss_recm (Integer n, const double mu[], double a[], double b[], double c[], NagError *fail)

## 3Description

nag_quad_1d_gauss_recm (d01tec) should only be used if the three-term recurrence cannot be determined analytically. A system of equations are formed, using the moments provided. This set of equations becomes ill-conditioned for moderate values of $n$, the number of abscissae and weights required. In most implementations quadruple precision calculation is used to maintain as much accuracy as possible.

## 4References

Golub G H and Welsch J H (1969) Calculation of Gauss quadrature rules Math. Comput. 23 221–230

## 5Arguments

1:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of weights and abscissae required.
Constraint: ${\mathbf{n}}>0$.
2:    $\mathbf{mu}\left[0:2*{\mathbf{n}}\right]$const doubleInput
On entry: ${\mathbf{mu}}\left(i\right)$ must contain the value of the moment with respect to ${x}^{i}$ i.e., , for $\mathit{i}=0,1,\dots ,2n$.
3:    $\mathbf{a}\left[{\mathbf{n}}\right]$doubleOutput
On exit: values helping define the three term recurrence used by nag_quad_1d_gauss_wrec (d01tdc).
4:    $\mathbf{b}\left[{\mathbf{n}}\right]$doubleOutput
On exit: values helping define the three term recurrence used by nag_quad_1d_gauss_wrec (d01tdc).
5:    $\mathbf{c}\left[{\mathbf{n}}\right]$doubleOutput
On exit: values helping define the three term recurrence used by nag_quad_1d_gauss_wrec (d01tdc).
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_DATA_ILL_CONDITIONED
The problem is too ill conditioned, it breaks down at row $〈\mathit{\text{value}}〉$.
NE_INT
The number of weights and abscissae requested (n) is less than $1$: ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

Internally quadruple precision is used to minimize loss of accuracy as much as possible.

## 8Parallelism and Performance

Because the function cannot check the validity of all the data presented, the user is advised to independently check the result, perhaps by integrating a function whose integral is known, using nag_quad_1d_gauss_recm (d01tec) and subsequently nag_quad_1d_gauss_wrec (d01tdc), to compare answers.

## 10Example

This example program uses nag_quad_1d_gauss_recm (d01tec) and moments to calculate a three-term recurrence relationship appropriate for Gauss–Legendre quadrature. It then uses the recurrence relationship to derive the weights and abscissae by calling nag_quad_1d_gauss_wrec (d01tdc).

### 10.1Program Text

Program Text (d01tece.c)

None.

### 10.3Program Results

Program Results (d01tece.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017