# NAG FL Interfaced01rgf (dim1_​fin_​gonnet_​vec)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

d01rgf is a general purpose integrator which calculates an approximation to the integral of a function $f\left(x\right)$ over a finite interval $\left[a,b\right]$:
 $I= ∫ab f(x) dx .$
The routine is suitable as a general purpose integrator, and can be used when the integrand has singularities and infinities. In particular, the routine can continue if the subroutine f explicitly returns a quiet or signalling NaN or a signed infinity.

## 2Specification

Fortran Interface
 Subroutine d01rgf ( a, b, f,
 Integer, Intent (Inout) :: iuser(*), ifail Integer, Intent (Out) :: nevals Real (Kind=nag_wp), Intent (In) :: a, b, epsabs, epsrel Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (Out) :: dinest, errest External :: f
#include <nag.h>
 void d01rgf_ (const double *a, const double *b, void (NAG_CALL *f)(const double x[], const Integer *nx, double fv[], Integer *iflag, Integer iuser[], double ruser[]),const double *epsabs, const double *epsrel, double *dinest, double *errest, Integer *nevals, Integer iuser[], double ruser[], Integer *ifail)
The routine may be called by the names d01rgf or nagf_quad_dim1_fin_gonnet_vec.

## 3Description

d01rgf uses the algorithm described in Gonnet (2010). It is an adaptive algorithm, similar to the QUADPACK routine QAGS (see Piessens et al. (1983), see also d01raf) but includes significant differences regarding how the integrand is represented, how the integration error is estimated and how singularities and divergent integrals are treated. The local error estimation is described in Gonnet (2010).
d01rgf requires a subroutine to evaluate the integrand at an array of different points and is, therefore, amenable to parallel execution.
Gonnet P (2010) Increasing the reliability of adaptive quadrature using explicit interpolants ACM Trans. Math. software 37 26
Piessens R, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag

## 5Arguments

1: $\mathbf{a}$Real (Kind=nag_wp) Input
On entry: $a$, the lower limit of integration.
2: $\mathbf{b}$Real (Kind=nag_wp) Input
On entry: $b$, the upper limit of integration. It is not necessary that $a.
Note: if ${\mathbf{a}}={\mathbf{b}}$, the routine will immediately return with ${\mathbf{dinest}}=0.0$, ${\mathbf{errest}}=0.0$ and ${\mathbf{nevals}}=0$.
3: $\mathbf{f}$Subroutine, supplied by the user. External Procedure
f must return the value of the integrand $f$ at a set of points.
The specification of f is:
Fortran Interface
 Subroutine f ( x, nx, fv,
 Integer, Intent (In) :: nx Integer, Intent (Inout) :: iflag, iuser(*) Real (Kind=nag_wp), Intent (In) :: x(nx) Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (Out) :: fv(nx)
 void f (const double x[], const Integer *nx, double fv[], Integer *iflag, Integer iuser[], double ruser[])
1: $\mathbf{x}\left({\mathbf{nx}}\right)$Real (Kind=nag_wp) array Input
On entry: the abscissae, ${x}_{i}$, for $\mathit{i}=1,2,\dots ,{\mathbf{nx}}$, at which function values are required.
2: $\mathbf{nx}$Integer Input
On entry: the number of abscissae at which a function value is required. nx will be of size equal to the number of Kronrod points in the quadrature rule used.
3: $\mathbf{fv}\left({\mathbf{nx}}\right)$Real (Kind=nag_wp) array Output
On exit: fv must contain the values of the integrand $f$. ${\mathbf{fv}}\left(i\right)=f\left({x}_{i}\right)$ for all $i=1,2,\dots ,{\mathbf{nx}}$.
4: $\mathbf{iflag}$Integer Input/Output
On entry: ${\mathbf{iflag}}=0$.
On exit: set ${\mathbf{iflag}}<0$ to force an immediate exit with ${\mathbf{ifail}}=-{\mathbf{1}}$.
5: $\mathbf{iuser}\left(*\right)$Integer array User Workspace
6: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
f is called with the arguments iuser and ruser as supplied to d01rgf. You should use the arrays iuser and ruser to supply information to f.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d01rgf is called. Arguments denoted as Input must not be changed by this procedure.
4: $\mathbf{epsabs}$Real (Kind=nag_wp) Input
On entry: the absolute accuracy required.
If epsabs is negative, $|{\mathbf{epsabs}}|$ is used. See Section 7.
If ${\mathbf{epsabs}}=0.0$, only the relative error will be used.
5: $\mathbf{epsrel}$Real (Kind=nag_wp) Input
On entry: the relative accuracy required.
If epsrel is negative, $|{\mathbf{epsrel}}|$ is used. See Section 7.
If ${\mathbf{epsrel}}=0.0$, only the absolute error will be used otherwise the actual value of epsrel used by d01rgf is .
Constraint: at least one of epsabs and epsrel must be nonzero.
6: $\mathbf{dinest}$Real (Kind=nag_wp) Output
On exit: the estimate of the definite integral f.
7: $\mathbf{errest}$Real (Kind=nag_wp) Output
On exit: the error estimate of the definite integral f.
8: $\mathbf{nevals}$Integer Output
On exit: the total number of points at which the integrand, $f$, has been evaluated.
9: $\mathbf{iuser}\left(*\right)$Integer array User Workspace
10: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
iuser and ruser are not used by d01rgf, but are passed directly to f and may be used to pass information to this routine.
11: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ 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:
Note: in some cases d01rgf may return useful information.
${\mathbf{ifail}}=1$
The requested accuracy was not achieved. Consider using larger values of epsabs and epsrel.
${\mathbf{ifail}}=2$
The integral is probably divergent or slowly convergent.
${\mathbf{ifail}}=14$
Both ${\mathbf{epsabs}}=0.0$ and ${\mathbf{epsrel}}=0.0$.
${\mathbf{ifail}}=-1$
Exit requested from f with ${\mathbf{iflag}}=⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

d01rgf cannot guarantee, but in practice usually achieves, the following accuracy:
 $|I-dinest| ≤ tol ,$
where
 $tol = max{|epsabs|,|epsrel|×|I|} ,$
and epsabs and epsrel are user-specified absolute and relative error tolerances. Moreover, it returns the quantity errest which, in normal circumstances, satisfies
 $|I-dinest| ≤ errest ≤ tol .$

## 8Parallelism and Performance

d01rgf is currently neither directly nor indirectly threaded. In particular, the user-supplied subroutine f is not called from within a parallel region initialized inside d01rgf.
The user-supplied subroutine f uses a vectorized interface, allowing for the required vector of function values to be evaluated in parallel; for example by placing appropriate OpenMP directives in the code for the user-supplied subroutine f.

The time taken by d01rgf depends on the integrand and the accuracy required.
d01rgf is suitable for evaluating integrals that have singularities within the requested interval.
In particular, d01rgf accepts non-finite values on return from the user-supplied subroutine f, and will adapt the integration rule accordingly to eliminate such points. Non-finite values include NaNs and infinities.

## 10Example

This example computes
 $∫ −1 1 sin(x) x ln(10⁢ (1-x)) .$

### 10.1Program Text

Program Text (d01rgfe.f90)

None.

### 10.3Program Results

Program Results (d01rgfe.r)