Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

## Purpose

nag_quad_1d_gen_vec_multi_rcomm (d01ra) is a general purpose adaptive integrator which calculates an approximation to a vector of definite integrals F$\mathbf{F}$ over a finite range [a,b] $\left[a,b\right]$, given the vector of integrands f(x)$\mathbf{f}\left(x\right)$.
 F = ∫ab f(x) d x $F = ∫ a b f(x) d x$
If the same subdivisions of the range are equally good for functions f1(x)${f}_{1}\left(x\right)$ and f2(x)${f}_{2}\left(x\right)$, because f1(x)${f}_{1}\left(x\right)$ and f2(x)${f}_{2}\left(x\right)$ have common areas of the range where they vary slowly and where they vary quickly, then we say that f1(x)${f}_{1}\left(x\right)$ and f2(x)${f}_{2}\left(x\right)$ are ‘similar’. nag_quad_1d_gen_vec_multi_rcomm (d01ra) is particularly effective for the integration of a vector of similar functions.

## Syntax

[irevcm, sid, needi, x, nx, dinest, errest, icom, com, ifail] = d01ra(irevcm, a, b, needi, x, nx, fm, dinest, errest, iopts, opts, icom, com, 'ni', ni, 'lenx', lenx)
[irevcm, sid, needi, x, nx, dinest, errest, icom, com, ifail] = nag_quad_1d_gen_vec_multi_rcomm(irevcm, a, b, needi, x, nx, fm, dinest, errest, iopts, opts, icom, com, 'ni', ni, 'lenx', lenx)

## Description

nag_quad_1d_gen_vec_multi_rcomm (d01ra) is an extension to various QUADPACK routines, including QAG, QAGS and QAWSE. The extensions made allow multiple integrands to be evaluated simultaneously, using a vectorized interface and reverse communication.
The quadrature scheme employed by nag_quad_1d_gen_vec_multi_rcomm (d01ra) can be chosen by you. Six Gauss–Kronrod schemes are available. The algorithm incorporates a global acceptance criterion (as defined by Malcolm and Simpson (1976)), optionally together with the ε-algorithm (see Wynn (1956)) to perform extrapolation. The local error estimation is described in Piessens et al. (1983).
nag_quad_1d_gen_vec_multi_rcomm (d01ra) is the integration function in the suite of functions nag_quad_1d_gen_vec_multi_rcomm (d01ra) and nag_quad_1d_gen_vec_multi_dimreq (d01rc). It also uses optional parameters, which can be set and queried using the functions nag_quad_opt_set (d01zk) and nag_quad_opt_get (d01zl) respectively. The options available are described in Section [Optional Parameters].
First, the option arrays iopts and opts must be initialized using nag_quad_opt_set (d01zk). Thereafter any required options must be set before calling nag_quad_1d_gen_vec_multi_rcomm (d01ra), or the function nag_quad_1d_gen_vec_multi_dimreq (d01rc). The options available are described in Section [Optional Parameters].
A typical usage of this suite of functions is (in pseudo-code for clarity),
Setup phase
```iopts = zeros(100, 1, nag_int_name);
opts  = zeros(100, 1);

% initialize option arrays
[iopts, opts, ifail] = d01zk('Initialize = d01ra', iopts, opts);

% set any non-default options required
[iopts, opts, ifail] = d01zk('option = value', iopts, opts);
...

% determine maximum required array lengths
[lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = ...
d01rc(ni, iopts, opts);

% allocate remaining arrays
needi  = zeros(ni, 1, nag_int_name);
com    = zeros(lcmax, 1);
icom   = zeros(licmax, 1, nag_int_name);
fm     = zeros(ldfmrq, sdfmrq);
dinest = zeros(ni, 1);
errest = zeros(ni, 1);
x      = zeros(1, lenxrq);
```
Solve phase
```irevcm = nag_int(1);

while irevcm ~= 0
[irevcm, sid, needi, x, nx, dinest, errest, icomm, comm, ifail] = ...
d01ra(irevcm, a, b, needi, x, nx, fm, dinest, errest, ...
iopts, opts, icom, com);

switch irevcm
case 11
Initial solve phase
evaluate fm(1:ni,1:nx)
case(12)
evaluate fm(needi(1:ni)=1,1:nx)
case(0)
Final return
end
```
Diagnostic phase
```[ivalue, rvalue, cvalue, optype, ifail] = d01zl('option', iopts, opts);
```
During the initial solve phase, the first estimation of the definite integral and error estimate is constructed over the interval [a,b] $\left[a,b\right]$. This will have been divided into spri ${s}_{\mathit{pri}}$ level 1$1$ segments, where spri ${s}_{\mathit{pri}}$ is the number of Primary Divisions, and will use any provided breakpoints if Primary Division Mode = MANUAL${\mathbf{Primary Division Mode}}=\mathrm{MANUAL}$.
Once a complete integral estimate over [a,b] $\left[a,b\right]$ is available, i.e., after all the estimates for the level 1 segments have been evaluated, the function enters the adaptive phase. The estimated errors are tested against the requested tolerances εa ${\epsilon }_{a}$ and εr ${\epsilon }_{r}$, corresponding to the Absolute Tolerance and Relative Tolerance respectively. Should this test fail, and additional subdivision be allowed, a segment is selected for subdivision, and is subsequently replaced by two new segments at the next level of refinement. How this segment is chosen may be altered by setting Prioritize Error to either favour the segment with the maximum error, or the segment with the lowest level supporting an unacceptable (although potentially non-maximal) error. Up to maxsdiv ${\mathrm{max}}_{\mathit{sdiv}}$ subdivisions are allowed provided sufficient memory, where maxsdiv ${\mathrm{max}}_{\mathit{sdiv}}$ is the value of Maximum Subdivisions.
Once a sufficient number of error estimates have been constructed for a particular integral, the function may optionally use Extrapolation to attempt to accelerate convergence. This may significantly lower the amount of work required for a given integration. To minimize the risk of premature convergence from extrapolation, a safeguard εsafe ${\epsilon }_{\mathit{safe}}$ can be set using Extrapolation Safeguard, and the extrapolated solution will only be considered if εsafe εq εex ${\epsilon }_{\mathit{safe}}{\epsilon }_{q}\le {\epsilon }_{\mathit{ex}}$, where εq ${\epsilon }_{q}$ and εex ${\epsilon }_{\mathit{ex}}$ are the estimated error directly from the quadrature and from the extrapolation respectively.

## References

Malcolm M A and Simpson R B (1976) Local versus global strategies for adaptive quadrature ACM Trans. Math. Software 1 129–146
Piessens R (1973) An algorithm for automatic integration Angew. Inf. 15 399–401
Piessens R, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag
Wynn P (1956) On a device for computing the em(Sn)${e}_{m}\left({S}_{n}\right)$ transformation Math. Tables Aids Comput. 10 91–96

## Parameters

Note: this function uses reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the parameter irevcm. Between intermediate exits and re-entries, all parameters other than irevcm, needi and fm must remain unchanged.

### Compulsory Input Parameters

1:     irevcm – int64int32nag_int scalar
On initial entry: irevcm = 1${\mathbf{irevcm}}=1$.
irevcm = 1${\mathbf{irevcm}}=1$
Set up data structures in icom and com and start a new integration.
Constraint: irevcm = 1${\mathbf{irevcm}}=1$ on initial entry.
On intermediate re-entry: irevcm should normally be left unchanged. However, if irevcm is set to a negative value, nag_quad_1d_gen_vec_multi_rcomm (d01ra) will terminate, (see irevcm = 11${\mathbf{irevcm}}=11$ and irevcm = 12${\mathbf{irevcm}}=12$ above).
2:     a – double scalar
a$a$, the lower bound of the domain.
3:     b – double scalar
b$b$, the upper bound of the domain.
If |ba| < 10ε$|b-a|<10\epsilon$, where ε$\epsilon$ is the machine precision (see nag_machine_precision (x02aj)), then nag_quad_1d_gen_vec_multi_rcomm (d01ra) will return dinest(j) = errest(j) = 0.0${\mathbf{dinest}}\left(\mathit{j}\right)={\mathbf{errest}}\left(\mathit{j}\right)=0.0$, for j = 1,2,,ni$\mathit{j}=1,2,\dots ,{n}_{i}$.
4:     needi(ni) – int64int32nag_int array
On initial entry: need not be set.
On intermediate re-entry: needi(j)${\mathbf{needi}}\left(j\right)$ may be used to indicate what action you have taken for integral j$j$.
needi(j) = 1${\mathbf{needi}}\left(j\right)=1$
You have provided the values fj(xi)${f}_{j}\left({x}_{\mathit{i}}\right)$ in fm(j,i)${\mathbf{fm}}\left(j,\mathit{i}\right)$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$.
needi(j) < 0${\mathbf{needi}}\left(j\right)<0$
You are abandoning the evaluation of integral j$j$. The current values of dinest(j)${\mathbf{dinest}}\left(j\right)$ and errest(j)${\mathbf{errest}}\left(j\right)$ will be returned on final completion.
Otherwise you have not provided the value fj(xi)${f}_{j}\left({x}_{i}\right)$.
5:     x(lenx) – double array
lenx, the dimension of the array, must satisfy the constraint lenxlenxrq${\mathbf{lenx}}\ge \mathit{lenxrq}$, where lenxrq$\mathit{lenxrq}$ is dependent upon the options currently set (see Section [Optional Parameters]). lenxrq$\mathit{lenxrq}$ is returned as lenxrq from nag_quad_1d_gen_vec_multi_dimreq (d01rc).
On initial entry: if Primary Division Mode = AUTOMATIC${\mathbf{Primary Division Mode}}=\mathrm{AUTOMATIC}$, x need not be set. This is the default behaviour.
If Primary Division Mode = MANUAL${\mathbf{Primary Division Mode}}=\mathrm{MANUAL}$, x may be used to supply a set of initial ‘break points’ inside the domain of integration. Specifically, x(i)${\mathbf{x}}\left(i\right)$ must contain a break point xi0${x}_{\mathit{i}}^{0}$, for i = 1,2,,(spri1)$\mathit{i}=1,2,\dots ,\left({s}_{\mathit{pri}}-1\right)$, where spri${s}_{\mathit{pri}}$ is the number of Primary Divisions.
Constraint: if break points are supplied, xi0(a,b)${x}_{\mathit{i}}^{0}\in \left(a,b\right)$, |xi0a| > 10.0ε$|{x}_{\mathit{i}}^{0}-a|>10.0\epsilon$, |xi0b| > 10.0ε$|{x}_{\mathit{i}}^{0}-b|>10.0\epsilon$, for i = 1,2,,(spri1)$\mathit{i}=1,2,\dots ,\left({s}_{\mathit{pri}}-1\right)$.
6:     nx – int64int32nag_int scalar
On initial entry: need not be set.
On intermediate re-entry: must not be changed.
7:     fm(ldfm, : $:$) – double array
The first dimension of the array fm must be at least ldfmrq$\mathit{ldfmrq}$, where ldfmrq$\mathit{ldfmrq}$ is dependent upon ni${n}_{i}$ and the options currently set. ldfmrq$\mathit{ldfmrq}$ is returned as ldfmrq from nag_quad_1d_gen_vec_multi_dimreq (d01rc). If default options are chosen, ldfmrq = ni$\mathit{ldfmrq}={n}_{i}$, implying ldfmni$\mathit{ldfm}\ge {\mathbf{ni}}$
The second dimension of the array must be at least sdfmrq$\mathit{sdfmrq}$, where sdfmrq$\mathit{sdfmrq}$ is dependent upon ni${n}_{i}$ and the options currently set. sdfmrq$\mathit{sdfmrq}$ is returned as sdfmrq from nag_quad_1d_gen_vec_multi_dimreq (d01rc). If default options are chosen, sdfmrq = lenxrq$\mathit{sdfmrq}=\mathit{lenxrq}$
On initial entry: need not be set.
On intermediate re-entry: if indicated by needi(j)${\mathbf{needi}}\left(j\right)$ you must supply the values fj(xi)${f}_{j}\left({x}_{i}\right)$ in fm(j,i)${\mathbf{fm}}\left(\mathit{j},\mathit{i}\right)$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$ and j = 1,2,,ni$\mathit{j}=1,2,\dots ,{n}_{i}$.
8:     dinest(ni) – double array
dinest(j)${\mathbf{dinest}}\left(j\right)$ contains the current estimate of the definite integral Fj${F}_{j}$.
On initial entry: need not be set.
On intermediate re-entry: must not be altered.
9:     errest(ni) – double array
errest(j)${\mathbf{errest}}\left(j\right)$ contains the current error estimate of the definite integral Fj${F}_{j}$.
On initial entry: need not be set.
On intermediate re-entry: must not be altered.
10:   iopts(100$100$) – int64int32nag_int array
Integer option array generated by nag_quad_opt_set (d01zk).
11:   opts(100$100$) – double array
Real option array generated by nag_quad_opt_set (d01zk).
12:   icom(licom) – int64int32nag_int array
licom, the dimension of the array, must satisfy the constraint licomlicmin$\mathit{licom}\ge \mathit{licmin}$, where licmin$\mathit{licmin}$ is dependent upon ni and the current options set. licmin$\mathit{licmin}$ is returned as licmin from nag_quad_1d_gen_vec_multi_dimreq (d01rc). If the default options are set, then licmin = 55 + 6 × ni$\mathit{licmin}=55+6×{\mathbf{ni}}$. Larger values than licmin$\mathit{licmin}$ are recommended if you anticipate that any integrals will require the domain to be further subdivided..
The contents of this array must not be changed directly once the integration process has started. icom contains details of the integration procedure, including information on the integration of the ni${n}_{i}$ integrals over individual segments. This data is stored sequentially in the order that segments are created. You are free to examine the contents of icom using the diagnostic function at any time during, or after, the integration process.
13:   com(lcom) – double array
lcom, the dimension of the array, must satisfy the constraint lcom > lcmin$\mathit{lcom}>\mathit{lcmin}$, where lcmin$\mathit{lcmin}$ is dependent upon ni, spri${s}_{\mathit{pri}}$ and the current options set. lcmin$\mathit{lcmin}$ is returned as lcmin from nag_quad_1d_gen_vec_multi_dimreq (d01rc). If default options are set, then lcmin = 96 + 12 × ni$\mathit{lcmin}=96+12×{\mathbf{ni}}$. Larger values are recommended if you anticipate that any integrals will require the domain to be further subdivided.
Given the current options and parameters, the maximum value, lcmax$\mathit{lcmax}$, of lcom that may be required, is returned as lcmax from nag_quad_1d_gen_vec_multi_dimreq (d01rc). If default options are chosen, lcmax = 94 + 9 × ni + ni / 2 + (spri + 100) × (2 + ni / 2 + 2 × ni)$\mathit{lcmax}=94+9×{\mathbf{ni}}+⌈{\mathbf{ni}}/2⌉+\left({s}_{\mathit{pri}}+100\right)×\left(2+⌈{\mathbf{ni}}/2⌉+2×{\mathbf{ni}}\right)$.
.
The contents of this array must not be changed directly once the integration process has started. com contains details of the integration procedure, including information on the integration of the ni${n}_{i}$ integrals over individual segments. This data is stored sequentially in the order that segments are created. You are free to examine the contents of com using the diagnostic function at any time during, or after, the solution phase.

### Optional Input Parameters

1:     ni – int64int32nag_int scalar
Default: The dimension of the arrays needi, dinest, errest and the first dimension of the array fm. (An error is raised if these dimensions are not equal.)
ni${n}_{i}$, number of integrands.
2:     lenx – int64int32nag_int scalar
Default: The dimension of the array x.
The dimension of the array x as declared in the (sub)program from which nag_quad_1d_gen_vec_multi_rcomm (d01ra) is called. Currently lenx = max (122,spri1)${\mathbf{lenx}}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(122,{s}_{\mathit{pri}}-1\right)$ will be sufficient for all cases.
Constraint: lenxlenxrq${\mathbf{lenx}}\ge \mathit{lenxrq}$, where lenxrq$\mathit{lenxrq}$ is dependent upon the options currently set (see Section [Optional Parameters]). lenxrq$\mathit{lenxrq}$ is returned as lenxrq from nag_quad_1d_gen_vec_multi_dimreq (d01rc).

ldfm licom lcom

### Output Parameters

1:     irevcm – int64int32nag_int scalar
On intermediate exit: irevcm = 11${\mathbf{irevcm}}=11$ or 12$12$.
irevcm requests the integrands fj(xi)${f}_{j}\left({x}_{i}\right)$ be evaluated for all required j1,,ni$j\in 1,\dots ,{n}_{i}$ as indicated by needi, and at all the points xi${x}_{\mathit{i}}$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$. Abscissae xi${x}_{i}$ are provided in x(i)${\mathbf{x}}\left(i\right)$ and fj(xi)${f}_{j}\left({x}_{i}\right)$ must be returned in fm(j,i)${\mathbf{fm}}\left(j,i\right)$.
During the initial solve phase:
irevcm = 11${\mathbf{irevcm}}=11$
Function values are required to construct the initial estimates of the definite integrals.
If needi(j) = 1${\mathbf{needi}}\left(j\right)=1$, fj(xi)${f}_{j}\left({x}_{i}\right)$ must be supplied in fm(j,i)${\mathbf{fm}}\left(j,i\right)$. This will be the case unless you have abandoned the evaluation of specific integrals on a previous call.
If needi(j) = 0${\mathbf{needi}}\left(j\right)=0$, you have previously abandoned the evaluation of integral j$j$, and hence should not supply the value of fj(xi)${f}_{j}\left({x}_{i}\right)$.
dinest and errest contain incomplete information during this phase. As such you should not abandon the evaluation of any integrals during this phase unless you do not require their estimate.
If irevcm is set to a negative value during this phase, needi(j)${\mathbf{needi}}\left(\mathit{j}\right)$, for j = 1,2,,ni$\mathit{j}=1,2,\dots ,{n}_{i}$, will be set to this negative value and ${\mathbf{ifail}}=-{\mathbf{1}}$ will be returned.
irevcm = 12${\mathbf{irevcm}}=12$
Function values are required to improve the estimates of the definite integrals.
If needi(j) = 0${\mathbf{needi}}\left(j\right)=0$, any evaluation of fj(xi)${f}_{j}\left({x}_{i}\right)$ will be discarded, so there is no need to provide them.
If needi(j) = 1${\mathbf{needi}}\left(j\right)=1$, fj(xi)${f}_{j}\left({x}_{i}\right)$ must be returned.
If needi(j) = 2${\mathbf{needi}}\left(j\right)=2$, 3$3$ or 4$4$, the current error estimate of integral j$j$ does not require integrand j$j$ to be evaluated. Should you choose to, integrand j$j$ can be evaluated in which case needi(j)${\mathbf{needi}}\left(j\right)$ must be set to 1$1$.
dinest and errest contain complete information during this phase.
If irevcm is set to a negative value during this phase either ${\mathbf{ifail}}={\mathbf{1}}$, 2${\mathbf{2}}$ or 3${\mathbf{3}}$ will be returned and the elements of needi will reflect the current state of of the adaptive process.
On final exit: irevcm = 0${\mathbf{irevcm}}=0$.
irevcm = 0${\mathbf{irevcm}}=0$
Indicates the algorithm has completed.
2:     sid – int64int32nag_int scalar
On intermediate exit: sid identifies a specific set of abscissae, x$\mathbf{x}$, returned during the integration process. When a new set of abscissae are generated the value of sid is incremented by 1$1$. Advanced users may store calculations required for an identified set x$\mathbf{x}$, and reuse them should nag_quad_1d_gen_vec_multi_rcomm (d01ra) return the same value of sid, i.e., the same set of abscissae was used.
3:     needi(ni) – int64int32nag_int array
On intermediate exit: needi(j)${\mathbf{needi}}\left(j\right)$ indicates what action must be taken for integral j = 1,2,ni$j=1,2,\dots {n}_{i}$ (see irevcm).
needi(j) = 0${\mathbf{needi}}\left(j\right)=0$
Do not provide fj(xi)${f}_{j}\left({x}_{i}\right)$. Any provided values will be ignored.
needi(j) = 1${\mathbf{needi}}\left(j\right)=1$
The values fj(xi)${f}_{j}\left({x}_{\mathit{i}}\right)$ must be provided in fm(j,i)${\mathbf{fm}}\left(j,\mathit{i}\right)$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$.
needi(j) = 2${\mathbf{needi}}\left(j\right)=2$
The values fj(xi)${f}_{j}\left({x}_{i}\right)$ are not definitely required, however the error estimate for integral j$j$ is still above the requested tolerance. If you wish to provide values for the evaluation of integral j$j$, set needi(j) = 1${\mathbf{needi}}\left(j\right)=1$, and supply fj(xi)${f}_{j}\left({x}_{\mathit{i}}\right)$ in fm(j,i)${\mathbf{fm}}\left(j,\mathit{i}\right)$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$.
needi(j) = 3${\mathbf{needi}}\left(j\right)=3$
The error estimate for integral j$j$ cannot be improved to below the requested tolerance directly, either because no more new splits may be performed due to exhaustion, or due to the detection of extremely bad integrand behaviour. However, providing the values fj(xi)${f}_{j}\left({x}_{i}\right)$ may still lead to some improvement, and may lead to an acceptable error estimate indirectly using Wynn's epsilon algorithm. If you wish to provide values for the evaluation of integral j$j$, set needi(j) = 1${\mathbf{needi}}\left(j\right)=1$, and supply fj(xi)${f}_{j}\left({x}_{\mathit{i}}\right)$ in fm(j,i)${\mathbf{fm}}\left(j,\mathit{i}\right)$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$.
needi(j) = 4${\mathbf{needi}}\left(j\right)=4$
The error estimate of integral j$j$ is below the requested tolerance. If you believe this to be false, if for example the result in dinest(j)${\mathbf{dinest}}\left(j\right)$ is greatly different to what you may expect, you may force the algorithm to re-evaluate this conclusion by including the evaluations of integrand j$j$ at xi${x}_{\mathit{i}}$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$, and setting needi(j) = 1${\mathbf{needi}}\left(j\right)=1$. Integral and error estimation will be performed again during the next iteration.
On final exit: needi(j)${\mathbf{needi}}\left(j\right)$ indicates the final state of integral j$j$.
needi(j) = 0${\mathbf{needi}}\left(j\right)=0$
The error estimate for Fj${F}_{j}$ is below the requested tolerance.
needi(j) = 1${\mathbf{needi}}\left(j\right)=1$
The error estimate for Fj${F}_{j}$ is below the requested tolerance after extrapolation.
needi(j) = 2${\mathbf{needi}}\left(j\right)=2$
The error estimate for Fj${F}_{j}$ is above the requested tolerance.
needi(j) = 3${\mathbf{needi}}\left(j\right)=3$
The error estimate for Fj${F}_{j}$ is above the requested tolerance, and extremely bad behaviour of integral j$j$ has been detected.
needi(j) < 0${\mathbf{needi}}\left(j\right)<0$
You prohibited further evaluation of integral j$j$.
4:     x(lenx) – double array
On intermediate exit: x(i)${\mathbf{x}}\left(\mathit{i}\right)$ is the abscissa xi${x}_{\mathit{i}}$, for i = 1,2,,nx$\mathit{i}=1,2,\dots ,{n}_{x}$, at which the appropriate integrals must be evaluated.
5:     nx – int64int32nag_int scalar
On intermediate exit: nx${n}_{x}$, the number of abscissae at which integrands are required.
6:     dinest(ni) – double array
dinest(j)${\mathbf{dinest}}\left(j\right)$ contains the current estimate of the definite integral Fj${F}_{j}$.
Contains the current estimates of the ni integrals. If irevcm = 0${\mathbf{irevcm}}=0$, this will be the final solution.
7:     errest(ni) – double array
errest(j)${\mathbf{errest}}\left(j\right)$ contains the current error estimate of the definite integral Fj${F}_{j}$.
Contains the current error estimates for the ni integrals. If irevcm = 0${\mathbf{irevcm}}=0$, errest contains the final error estimates of the ni integrals.
8:     icom(licom) – int64int32nag_int array
9:     com(lcom) – double array
10:   ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_quad_1d_gen_vec_multi_rcomm (d01ra) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail = 1${\mathbf{ifail}}=1$
At least one error estimate exceeded the requested tolerances.
W ifail = 2${\mathbf{ifail}}=2$
Extremely bad behaviour was detected for at least one integral.
W ifail = 3${\mathbf{ifail}}=3$
Extremely bad behaviour was detected for at least one integral. At least one other integral error estimate was above the requested tolerance.
ifail = 11${\mathbf{ifail}}=11$
ifail = 21${\mathbf{ifail}}=21$
Constraint: ni1${\mathbf{ni}}\ge 1$.
ifail = 71${\mathbf{ifail}}=71$
On entry, Primary Division Mode = MANUAL${\mathbf{Primary Division Mode}}=\mathrm{MANUAL}$ and at least one supplied breakpoint in x is outside of the domain of integration.
ifail = 81${\mathbf{ifail}}=81$
ifail = 111${\mathbf{ifail}}=111$
W ifail = 171${\mathbf{ifail}}=171$
W ifail = 191${\mathbf{ifail}}=191$
ifail = 1001${\mathbf{ifail}}=1001$
Either the option arrays iopts and opts have not been initialized for nag_quad_1d_gen_vec_multi_rcomm (d01ra), or they have become corrupted.
ifail = 1101${\mathbf{ifail}}=1101$
On entry, one of icom and com has become corrupted.
W ifail = 1${\mathbf{ifail}}=-1$
Evaluation of all integrals has been stopped during the initial phase.

## Accuracy

nag_quad_1d_gen_vec_multi_rcomm (d01ra) cannot guarantee, but in practice usually achieves, the following accuracy for each integral Fj${F}_{j}$:
 |Fj − dinest(j)| ≤ tol $| Fj - dinestj | ≤ tol$
where
 tol = max (εa, εr × |Fj| ) $tol = max(εa, εr × |Fj| )$
εa${\epsilon }_{a}$ and εr${\epsilon }_{r}$ are the error tolerances Absolute Tolerance and Relative Tolerance respectively. Moreover, it returns errest, the entries of which in normal circumstances satisfy,
 |Fj − dinest(j)| ≤ errest(j) ≤ tol . $| Fj - dinestj | ≤ errestj ≤ tol .$

The time required by nag_quad_1d_gen_vec_multi_rcomm (d01ra) is usually dominated by the time required to evaluate the values of the integrands fj${f}_{j}$.
nag_quad_1d_gen_vec_multi_rcomm (d01ra) will be most efficient if any badly behaved integrands provided have irregularities over similar subsections of the domain. For example, evaluation of the integrals,
∫ 01
 log(x) x − (1/2) x2
dx
$∫ 0 1 log(x) x-12 x2 dx$
will be quite efficient, as the irregular behaviour of the first two integrands is at x = 0$x=0$. On the contrary, the evaluation of the integrals,
01
 ( log(x) ) log(1 − x)
dx
$∫ 0 1 log(x) log(1-x) dx$
will be less efficient, as the two integrands have singularities at opposite ends of the domain, which will result in subdivisions which are only of use to one integrand. In such cases, it will be more efficient to use two sets of calls to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
nag_quad_1d_gen_vec_multi_rcomm (d01ra) will flag extremely bad behaviour if a sub-interval k $\stackrel{-}{k}$ with bounds [ak,bk] $\left[{a}_{\stackrel{-}{k}},{b}_{\stackrel{-}{k}}\right]$ satisfying |bkak| < max (δa, δr × |ba| ) $|{b}_{\stackrel{-}{k}}-{a}_{\stackrel{-}{k}}|<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\delta }_{a},{\delta }_{r}×|b-a|\right)$ has a local error estimate greater than the requested tolerance for at least one integral. The values δa${\delta }_{a}$ and δr${\delta }_{r}$ can be set through the optional parameters Absolute Interval Minimum and Relative Interval Minimum respectively. You may try using nag_quad_1d_gen_vec_multi_rcomm (d01ra) again over such sub-intervals with only the integrands that exhibited bad behaviour and a new set of communication arrays, or you may use another quadrature routine designed to deal with any known specific singular behaviour over this sub-interval. If these provide sufficient accuracy over the specific sub-intervals, you may correct the definite integral evaluations over [a,b]$\left[a,b\right]$ by subtracting the inadequate sub-interval estimations from dinest and errest and adding the acceptable sub-interval estimations generated by the direct integration of the sub-interval where bad behaviour was detected.

## Example

```function nag_quad_1d_gen_vec_multi_rcomm_example

% Setup phase.

% set problem parameters
ni = int64(2);
nx = int64(0);
% lower (a) and upper (b) bounds
a = 0;
b = pi;
iopts = zeros(100, 1, 'int64');
opts  = zeros(100, 1);

% initialize option arrays

% set any non-default options required
[iopts, opts, ifail] = nag_quad_opt_set('Absolute Tolerance = 1.0e-7', iopts, opts);
[iopts, opts, ifail] = nag_quad_opt_set('Relative Tolerance = 1.0e-7', iopts, opts);

% determine maximum required array lengths
[lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = ...

% allocate remaining arrays
needi  = zeros(ni, 1, 'int64');
comm   = zeros(lcmax, 1);
icomm  = zeros(licmax, 1, 'int64');
fm     = zeros(ldfmrq, sdfmrq);
dinest = zeros(ni, 1);
errest = zeros(ni, 1);
x      = zeros(1, lenxrq);

% Solve phase.

% Use nag_quad_1d_gen_vec_multi_rcomm to evaluate the definate integrals of:
%   f_1 = (x*sin(2*x))*cos(15*x)
%   f_2 = (x*sin(2*x))*(x*cos(50*x))

% set initial irevcm
irevcm = int64(1);

while irevcm ~= 0
[irevcm, sid, needi, x, nx, dinest, errest, icomm, comm, ifail] = ...
nag_quad_1d_gen_vec_multi_rcomm(irevcm, a, b, needi, x, nx, fm, dinest, errest, ...
iopts, opts, icomm, comm);

switch irevcm
case 11
% Initial returns.
% These will occur during the non-adaptive phase.
% All values must be supplied.
% dinest and errest do not contain approximations
% over the complete interval at this stage.

% Calculate x*sin(2*x), storing the result in fm(2,1:nx) for re-use.
fm(2, :) = x.*sin(2*x);

% Calculate f_1
fm(1, :) = fm(2, :).*cos(15*x);

% Calculate f_2
fm(2, :) = fm(2, :).*x.*cos(50*x);
case 12
% Intermediate returns.
% These will occur during the adaptive phase.
% All requested values must be supplied.
% dinest and errest do not contain approximations
% over the complete interval at this stage.

% Calculate x*sin(2*x).
fm(2, :) = x.*sin(2*x);

% Calculate f_1 if required
if needi(1) == 1
fm(1, :) = fm(2, :).*cos(15*x);
end

% Complete f_2 calculation if required.
if needi(2) == 1
fm(2, :) = fm(2, :).*x.*cos(50*x);
end
case 0
% Final return
end
end

% query some currently set options and statistics.
[ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Maximum Subdivisions', iopts, opts);
display_option('Maximum Subdivisions',optype,ivalue,rvalue,cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Extrapolation', iopts, opts);
display_option('Extrapolation',optype,ivalue,rvalue,cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Extrapolation Safeguard', iopts, opts);
display_option('Extrapolation Safeguard',optype,ivalue,rvalue,cvalue);

% print solution
fprintf('\nIntegral |  needi  |   dinest   |   errest   \n');
for j=1:ni
fprintf('%9d %9d %12.4e %12.4e\n', j, needi(j), dinest(j), errest(j));
end

function [dinest, errest, user] = monit(ni, ns, dinest, errest, fcount, ...
sinfoi, evals, ldi, sinfor, fs, ...
es, ldr, user)
% Display information on individual segments
fprintf('\nInformation on splitting and evaluations over subregions.\n');
for k=1:ns
sid = sinfoi(1,k);
parent = sinfoi(2,k);
child1 = sinfoi(3,k);
child2 = sinfoi(4,k);
level = sinfoi(5,k);
lbnd = sinfor(1,k);
ubnd = sinfor(2,k);
fprintf('\nSegment %3d Sid = %3d Parent = %3d Level = %3d.\n', k, sid, parent, level);
if (child1>0)
fprintf('Children = (%3d, %3d)\n', child1, child2);
end
fprintf('Bounds (%11.4e, %11.4e)\n', lbnd, ubnd);
for j = 1:ni
if (evals(j,k) ~= 0)
fprintf('Integral %2d approximation %11.4e\n', j, fs(j,k));
fprintf('Integral %2d error estimate %11.4e\n', j, es(j,k));
if (evals(j,k) ~= 1)
fprintf('Integral %2d evaluation has been superseded by descendants.\n', j);
end
end
end
end
function display_option(optstr,optype,ivalue,rvalue,cvalue)
% Query optype and print the appropriate option values

switch optype
case 1
fprintf('%30s: %13d\n', optstr, ivalue);
case 2
fprintf('%30s: %13.4e\n', optstr, rvalue);
case 3
fprintf('%30s: %16s\n', optstr, cvalue);
case 4
fprintf('%30s: %3d  %16s\n', optstr, ivalue, cvalue);
case 5
fprintf('%30s: %14.4e  %16s\n', optstr, rvalue, cvalue);
end
```
```
Maximum Subdivisions:            50
Extrapolation: ON
Extrapolation Safeguard:    1.0000e-12

Integral |  needi  |   dinest   |   errest
1         0  -2.8431e-02   1.1234e-14
2         0   7.9083e-03   2.6600e-09

```
```function d01ra_example

% Setup phase.

% set problem parameters
ni = int64(2);
nx = int64(0);
% lower (a) and upper (b) bounds
a = 0;
b = pi;
iopts = zeros(100, 1, 'int64');
opts  = zeros(100, 1);

% initialize option arrays
[iopts, opts, ifail] = d01zk('Initialize = d01ra', iopts, opts);

% set any non-default options required
[iopts, opts, ifail] = d01zk('Quadrature Rule = gk41', iopts, opts);
[iopts, opts, ifail] = d01zk('Absolute Tolerance = 1.0e-7', iopts, opts);
[iopts, opts, ifail] = d01zk('Relative Tolerance = 1.0e-7', iopts, opts);

% determine maximum required array lengths
[lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = ...
d01rc(ni, iopts, opts);

% allocate remaining arrays
needi  = zeros(ni, 1, 'int64');
comm   = zeros(lcmax, 1);
icomm  = zeros(licmax, 1, 'int64');
fm     = zeros(ldfmrq, sdfmrq);
dinest = zeros(ni, 1);
errest = zeros(ni, 1);
x      = zeros(1, lenxrq);

% Solve phase.

% Use d01ra to evaluate the definate integrals of:
%   f_1 = (x*sin(2*x))*cos(15*x)
%   f_2 = (x*sin(2*x))*(x*cos(50*x))

% set initial irevcm
irevcm = int64(1);

while irevcm ~= 0
[irevcm, sid, needi, x, nx, dinest, errest, icomm, comm, ifail] = ...
d01ra(irevcm, a, b, needi, x, nx, fm, dinest, errest, ...
iopts, opts, icomm, comm);

switch irevcm
case 11
% Initial returns.
% These will occur during the non-adaptive phase.
% All values must be supplied.
% dinest and errest do not contain approximations
% over the complete interval at this stage.

% Calculate x*sin(2*x), storing the result in fm(2,1:nx) for re-use.
fm(2, :) = x.*sin(2*x);

% Calculate f_1
fm(1, :) = fm(2, :).*cos(15*x);

% Calculate f_2
fm(2, :) = fm(2, :).*x.*cos(50*x);
case 12
% Intermediate returns.
% These will occur during the adaptive phase.
% All requested values must be supplied.
% dinest and errest do not contain approximations
% over the complete interval at this stage.

% Calculate x*sin(2*x).
fm(2, :) = x.*sin(2*x);

% Calculate f_1 if required
if needi(1) == 1
fm(1, :) = fm(2, :).*cos(15*x);
end

% Complete f_2 calculation if required.
if needi(2) == 1
fm(2, :) = fm(2, :).*x.*cos(50*x);
end
case 0
% Final return
end
end

% query some currently set options and statistics.
[ivalue, rvalue, cvalue, optype, ifail] = d01zl('Quadrature rule', iopts, opts);
[ivalue, rvalue, cvalue, optype, ifail] = d01zl('Maximum Subdivisions', iopts, opts);
display_option('Maximum Subdivisions',optype,ivalue,rvalue,cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = d01zl('Extrapolation', iopts, opts);
display_option('Extrapolation',optype,ivalue,rvalue,cvalue);
[ivalue, rvalue, cvalue, optype, ifail] = d01zl('Extrapolation Safeguard', iopts, opts);
display_option('Extrapolation Safeguard',optype,ivalue,rvalue,cvalue);

% print solution
fprintf('\nIntegral |  needi  |   dinest   |   errest   \n');
for j=1:ni
fprintf('%9d %9d %12.4e %12.4e\n', j, needi(j), dinest(j), errest(j));
end

function [dinest, errest, user] = monit(ni, ns, dinest, errest, fcount, ...
sinfoi, evals, ldi, sinfor, fs, ...
es, ldr, user)
% Display information on individual segments
fprintf('\nInformation on splitting and evaluations over subregions.\n');
for k=1:ns
sid = sinfoi(1,k);
parent = sinfoi(2,k);
child1 = sinfoi(3,k);
child2 = sinfoi(4,k);
level = sinfoi(5,k);
lbnd = sinfor(1,k);
ubnd = sinfor(2,k);
fprintf('\nSegment %3d Sid = %3d Parent = %3d Level = %3d.\n', k, sid, parent, level);
if (child1>0)
fprintf('Children = (%3d, %3d)\n', child1, child2);
end
fprintf('Bounds (%11.4e, %11.4e)\n', lbnd, ubnd);
for j = 1:ni
if (evals(j,k) ~= 0)
fprintf('Integral %2d approximation %11.4e\n', j, fs(j,k));
fprintf('Integral %2d error estimate %11.4e\n', j, es(j,k));
if (evals(j,k) ~= 1)
fprintf('Integral %2d evaluation has been superseded by descendants.\n', j);
end
end
end
end
function display_option(optstr,optype,ivalue,rvalue,cvalue)
% Query optype and print the appropriate option values

switch optype
case 1
fprintf('%30s: %13d\n', optstr, ivalue);
case 2
fprintf('%30s: %13.4e\n', optstr, rvalue);
case 3
fprintf('%30s: %16s\n', optstr, cvalue);
case 4
fprintf('%30s: %3d  %16s\n', optstr, ivalue, cvalue);
case 5
fprintf('%30s: %14.4e  %16s\n', optstr, rvalue, cvalue);
end
```
```
Maximum Subdivisions:            50
Extrapolation: ON
Extrapolation Safeguard:    1.0000e-12

Integral |  needi  |   dinest   |   errest
1         0  -2.8431e-02   1.1234e-14
2         0   7.9083e-03   2.6600e-09

```

## Optional Parameters

This section can be skipped if you wish to use the default values for all optional parameters, otherwise, the following is a list of the optional parameters available. A full description of each optional parameter is provided in Section [Description of the optional parameters].

### Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
• the keywords, where the minimum abbreviation of each keyword is underlined;
• a parameter value, where the letters a$a$, i​ and ​r$i\text{​ and ​}r$ denote options that take character, integer and real values respectively;
• the default value.
The following symbol represents various machine constants:
All options accept the value ‘DEFAULT’ in order to return single options to their default states.
Keywords and character values are case insensitive, however they must be separated by at least one space.
For nag_quad_1d_gen_vec_multi_rcomm (d01ra) the maximum length of the parameter cvalue used by nag_quad_opt_get (d01zl) is 15$15$.
Absolute Interval Minimum  r$r$
Default = 128.0ε$\text{}=128.0\epsilon$
r = δa$r={\delta }_{a}$, the absolute lower limit for a segment to be considered for subdivision. See also Relative Interval Minimum and Section [Further Comments].
Constraint: r128ε$r\ge 128\epsilon$.
Absolute Tolerance  r$r$
Default = 1024ε$\text{}=1024\epsilon$
r = εa$r={\epsilon }_{a}$, the absolute tolerance required. See also Relative Tolerance and Section [Description].
Constraint: r0.0$r\ge 0.0$.
Extrapolation  a$a$
Default = ON$\text{}=\mathrm{ON}$
Activate or deactivate the use of the ε$\epsilon$ algorithm (Wynn (1956)). Extrapolation often reduces the number of iterations required to achieve the desired solution, but it can occasionally lead to premature convergence towards an incorrect answer.
ON$\mathrm{ON}$
Use extrapolation.
OFF$\mathrm{OFF}$
Disable extrapolation.
Extrapolation Safeguard  r$r$
Default = 1.0e−12$\text{}=\text{1.0e−12}$
r = εsafe$r={\epsilon }_{\mathit{safe}}$. If εq${\epsilon }_{q}$ is the estimated error from the quadrature evaluation alone, and εex${\epsilon }_{\mathit{ex}}$ is the error estimate determined using extrapolation, then the extrapolated solution will only be accepted if εsafe εq εex${\epsilon }_{\mathit{safe}}{\epsilon }_{q}\le {\epsilon }_{\mathit{ex}}$.
Maximum Subdivisions  i$i$
Default = 50$\text{}=50$
i = maxsdiv$i={\mathrm{max}}_{\mathit{sdiv}}$, the maximum number of subdivisions the algorithm may use in the adaptive phase, forming at most an additional (2 × maxsdiv) $\left(2×{\mathrm{max}}_{\mathit{sdiv}}\right)$ segments.
Primary Divisions  i$i$
Default = 1$\text{}=1$
i = spri$i={s}_{\mathit{pri}}$, the number of initial segments of the domain [a,b]$\left[a,b\right]$. By default the initial segment is the entire domain.
Constraint: 0 < i < 1000000$0.
Primary Division Mode  a$a$
Default = AUTOMATIC$\text{}=\text{AUTOMATIC}$
Determines how the initial set of spri${s}_{\mathit{pri}}$ segments will be generated.
AUTOMATIC
nag_quad_1d_gen_vec_multi_rcomm (d01ra) will automatically generate spri${s}_{\mathit{pri}}$ segments of equal size covering the interval [a,b]$\left[a,b\right]$.
MANUAL
nag_quad_1d_gen_vec_multi_rcomm (d01ra) will use the break points xi0${x}_{\mathit{i}}^{0}$, for i = 1,2,,spri1$\mathit{i}=1,2,\dots ,{s}_{\mathit{pri}}-1$, supplied in x on initial entry to generate the initial segments covering [a,b]$\left[a,b\right]$. These may be supplied in any order, however it will be more efficient to supply them in ascending (or descending if a > b$a>b$) order. Repeated break points are allowed, although this will generate fewer initial segments.
Note: an absolute bound on the size of an initial segment of 10.0ε$10.0\epsilon$ is automatically applied in all cases, and will result in fewer initial subdivisions being generated if automatically generated or supplied breakpoints result in segments smaller than this..
Prioritize Error  a$a$
Default = LEVEL$\text{}=\text{LEVEL}$
Indicates how new subdivisions of segments sustaining unacceptable local errors for integrals should be prioritized.
LEVEL$\text{LEVEL}$
Segments with lower level with unsatisfactory error estimates will be chosen over segments with greater error on higher levels. This will probably lead to more integrals being improved in earlier iterations of the algorithm, and hence will probably lead to fewer repeated returns (see parameter sid), and to more integrals being satisfactorily estimated if computational exhaustion occurs.
MAXERR$\text{MAXERR}$
The segment with the worst overall error will be split, regardless of level. This will more rapidly improve the worst integral estimates, although it will probably result in the fewest integrals being improved in earlier iterations, and may hence lead to more repeated returns (see parameter sid), and potentially fewer integrals satisfying the requested tolerances if computational exhaustion occurs.
Quadrature Rule  a$a$
Default = GK15$\text{}=\text{GK15}$
The basic quadrature rule to be used during the integration. Currently 6$6$ Gauss–Kronrod rules are available, all identifiable by the letters GK followed by the number of points required by the Kronrod rule. Higher order rules generally provide higher accuracy with fewer subdivisons. However, for integrands with sharp singularities, lower order rules may be more efficient, particularly if the integrand away from the singularity is well behaved. With higher order rules, you may need to increase the Absolute Interval Minimum and the Relative Interval Minimum to maintain numerical difference between the abscissae and the segment bounds.
GK15
The Gauss–Kronrod rule based on 7$7$ Gauss points and 15$15$ Kronrod points.
GK21
The Gauss–Kronrod rule based on 10$10$ Gauss points and 21$21$ Kronrod points. This is the rule used by nag_quad_1d_fin_bad_vec (d01at)
GK31
The Gauss–Kronrod rule based on 15$15$ Gauss points and 31$31$ Kronrod points.
GK41
The Gauss–Kronrod rule based on 20$20$ Gauss points and 41$41$ Kronrod points.
GK51
The Gauss–Kronrod rule based on 25$25$ Gauss points and 51$51$ Kronrod points.
GK61
The Gauss–Kronrod rule based on 30$30$ Gauss points and 61$61$ Kronrod points. This is the highest order rule, most suitable for highly oscilliatory integrals.
Relative Interval Minimum  r$r$
Default = 1.0e−6$\text{}=\text{1.0e−6}$
r = δr$r={\delta }_{r}$, the relative factor in the lower limit, δr|ba|${\delta }_{r}|b-a|$, for a segment to be considered for subdivision. See also Absolute Interval Minimum and Section [Further Comments].
Constraint: r0.0$r\ge 0.0$.
Relative Tolerance  r$r$
Default = sqrt(ε)$\text{}=\sqrt{\epsilon }$
r = εr$r={\epsilon }_{r}$, the required relative tolerance. See also Absolute Tolerance and Section [Description].
Constraint: r0.0$r\ge 0.0$.
Note: setting both εr = εa = 0.0${\epsilon }_{r}={\epsilon }_{a}=0.0$ is possible, although it will most likely result in an excessive amount of computational effort.