# NAG CL Interfaced01rgc (dim1_​fin_​gonnet_​vec)

Settings help

CL Name Style:

## 1Purpose

d01rgc 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 function is suitable as a general purpose integrator, and can be used when the integrand has singularities and infinities. In particular, the function can continue if the function f explicitly returns a quiet or signalling NaN or a signed infinity.

## 2Specification

 #include
void  d01rgc (double a, double b,
 void (*f)(const double x[], Integer nx, double fv[], Integer *iflag, Nag_Comm *comm),
double epsabs, double epsrel, double *dinest, double *errest, Integer *nevals, Nag_Comm *comm, NagError *fail)
The function may be called by the names: d01rgc, nag_quad_dim1_fin_gonnet_vec or nag_quad_1d_fin_gonnet_vec.

## 3Description

d01rgc 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 d01rac) 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).
d01rgc requires a function to evaluate the integrand at an array of different points and is, therefore, amenable to parallel execution.

## 4References

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}$double Input
On entry: $a$, the lower limit of integration.
2: $\mathbf{b}$double Input
On entry: $b$, the upper limit of integration. It is not necessary that $a.
Note: if ${\mathbf{a}}={\mathbf{b}}$, the function will immediately return with ${\mathbf{dinest}}=0.0$, ${\mathbf{errest}}=0.0$ and ${\mathbf{nevals}}=0$.
3: $\mathbf{f}$function, supplied by the user External Function
f must return the value of the integrand $f$ at a set of points.
The specification of f is:
 void f (const double x[], Integer nx, double fv[], Integer *iflag, Nag_Comm *comm)
1: $\mathbf{x}\left[\mathit{dim}\right]$const double 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[\mathit{dim}\right]$double Output
On exit: fv must contain the values of the integrand $f$. ${\mathbf{fv}}\left[i-1\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{fail}}\mathbf{.}\mathbf{code}=$ NE_USER_STOP.
5: $\mathbf{comm}$Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to f.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling d01rgc you may allocate memory and initialize these pointers with various quantities for use by f when called from d01rgc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
4: $\mathbf{epsabs}$double 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}$double 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 d01rgc is .
Constraint: at least one of epsabs and epsrel must be nonzero.
6: $\mathbf{dinest}$double * Output
On exit: the estimate of the definite integral f.
7: $\mathbf{errest}$double * 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{comm}$Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
10: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ACCURACY
The requested accuracy was not achieved. Consider using larger values of epsabs and epsrel.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONVERGENCE
The integral is probably divergent or slowly convergent.
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 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_TOO_SMALL
Both ${\mathbf{epsabs}}=0.0$ and ${\mathbf{epsrel}}=0.0$.
NE_USER_STOP
Exit requested from f with ${\mathbf{iflag}}=⟨\mathit{\text{value}}⟩$.

## 7Accuracy

d01rgc 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

d01rgc is currently neither directly nor indirectly threaded. In particular, the user-supplied function f is not called from within a parallel region initialized inside d01rgc.
The user-supplied function 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 function f.

The time taken by d01rgc depends on the integrand and the accuracy required.
d01rgc is suitable for evaluating integrals that have singularities within the requested interval.
In particular, d01rgc accepts non-finite values on return from the user-supplied function 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 (d01rgce.c)

None.

### 10.3Program Results

Program Results (d01rgce.r)