# NAG Library Routine Document

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine d01ubf ( fun, n, ans,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: iuser(*), ifail Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (Out) :: ans External :: fun
#include nagmk26.h
 void d01ubf_ (void (NAG_CALL *fun)(const double x[], double f[], const Integer *n, Integer iuser[], double ruser[], Integer *istop),const Integer *n, double *ans, Integer iuser[], double ruser[], Integer *ifail)

## 3Description

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$.
Golub G H and Welsch J H (1969) Calculation of Gauss quadrature rules Math. Comput. 23 221–230

## 5Arguments

1:     $\mathbf{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:
Fortran Interface
 Subroutine fun ( x, f, n,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: iuser(*), istop Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (Out) :: f(n)
#include nagmk26.h
 void fun (const double x[], double f[], const Integer *n, Integer iuser[], double ruser[], Integer *istop)
1:     $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the points at which the integrand function $f$ must be evaluated.
2:     $\mathbf{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:     $\mathbf{n}$ – IntegerInput
On entry: n specifies the number of weights and abscissae to be used.
4:     $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
5:     $\mathbf{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:     $\mathbf{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:     $\mathbf{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:     $\mathbf{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:     $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
5:     $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace
iuser and ruser are not used by d01ubf, but are passed directly to fun and may be used to pass information to this routine.
6:     $\mathbf{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).

## 6Error 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$
An unexpected error has been triggered by this routine. Please contact NAG.
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.

## 7Accuracy

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

## 8Parallelism and Performance

d01ubf is not threaded in any implementation.

None.

## 10Example

This example computes an approximation to .

### 10.1Program Text

Program Text (d01ubfe.f90)

None.

### 10.3Program Results

Program Results (d01ubfe.r)

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