D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentD01UBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

D01UBF returns the Gaussian quadrature approximation for the specific problem . The degrees of precision catered for are: $1$, $3$, $5$, $7$, $9$, $19$, $29$, $39$ and $49$, corresponding to values of $n=1$, $2$, $3$, $4$, $5$, $10$, $15$, $20$ and $25$, where $n$ is the number of weights.

## 2  Specification

 SUBROUTINE D01UBF ( FUN, N, ANS, IUSER, RUSER, IFAIL)
 INTEGER N, IUSER(*), IFAIL REAL (KIND=nag_wp) ANS, RUSER(*) EXTERNAL FUN

## 3  Description

D01UBF uses the weights ${w}_{i}$ and the abscissae ${x}_{i}$ such that $\underset{0}{\overset{\infty }{\int }}\mathrm{exp}\left({-x}^{2}\right)f\left(x\right)$ is approximated by $\sum _{\mathit{i}=1}^{n}{w}_{i}f\left({x}_{i}\right)$ to maximum precision i.e., it is exact when $f\left(x\right)$ is a polynomial of degree $2n-1$.

## 4  References

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

## 5  Arguments

1:     $\mathrm{FUN}$ – SUBROUTINE, supplied by the user.External Procedure
FUN must return the integrands $f\left({x}_{i}\right)$ in ${\mathbf{F}}\left(\mathit{i}\right)$ for each ${x}_{i}$ in ${\mathbf{X}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$ at a given point.
The specification of FUN is:
 SUBROUTINE FUN ( X, F, N, IUSER, RUSER, ISTOP)
 INTEGER N, IUSER(*), ISTOP REAL (KIND=nag_wp) X(N), F(N), RUSER(*)
1:     $\mathrm{X}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the points at which the integrand function $f$ must be evaluated.
2:     $\mathrm{F}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{F}}\left(\mathit{i}\right)$ must contain the value of the integrand $f\left({x}_{i}\right)$ evaluated at the point ${\mathbf{X}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
3:     $\mathrm{N}$ – INTEGERInput
On entry: N specifies the number of weights and abscissae to be used.
4:     $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
5:     $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace
FUN is called with the arguments IUSER and RUSER as supplied to D01UBF. You should use the arrays IUSER and RUSER to supply information to FUN.
6:     $\mathrm{ISTOP}$ – INTEGERInput/Output
On entry: ${\mathbf{ISTOP}}=0$.
On exit: you may set ISTOP to a negative number if at any time it is impossible to evaluate the function $f\left(x\right)$. In this case D01UBF halts with IFAIL set to the value of ISTOP and the value returned in ANS will be that of a non-signalling NaN.
FUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D01UBF is called. Arguments denoted as Input must not be changed by this procedure.
2:     $\mathrm{N}$ – INTEGERInput
On entry: N specifies the number of weights and abscissae to be used.
Constraint: ${\mathbf{N}}=1$, $2$, $3$, $4$, $5$, $10$, $15$, $20$ or $25$.
3:     $\mathrm{ANS}$ – REAL (KIND=nag_wp)Output
On exit: if ${\mathbf{IFAIL}}=0$, ANS contains an approximation to the integral. Otherwise, ANS will be a non-signalling NaN.
4:     $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
5:     $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace
IUSER and RUSER are not used by D01UBF, but are passed directly to FUN and should be used to pass information to this routine.
6:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}<0$
The user has halted the calculation.
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{N}}\le 25$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
N is not one of the allowed values.
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7  Accuracy

The weights and abscissae have been calculated using quadruple precision arithmetic.

## 8  Parallelism and Performance

D01UBF is not threaded in any implementation.

None.

## 10  Example

This example computes an approximation to .

### 10.1  Program Text

Program Text (d01ubfe.f90)

None.

### 10.3  Program Results

Program Results (d01ubfe.r)