NAG Library Routine Document
D01EAF
1 Purpose
D01EAF computes approximations to the integrals of a vector of similar functions, each defined over the same multidimensional hyperrectangular region. The routine uses an adaptive subdivision strategy, and also computes absolute error estimates.
2 Specification
SUBROUTINE D01EAF ( 
NDIM, A, B, MINCLS, MAXCLS, NFUN, FUNSUB, ABSREQ, RELREQ, LENWRK, WRKSTR, FINEST, ABSEST, IFAIL) 
INTEGER 
NDIM, MINCLS, MAXCLS, NFUN, LENWRK, IFAIL 
REAL (KIND=nag_wp) 
A(NDIM), B(NDIM), ABSREQ, RELREQ, WRKSTR(LENWRK), FINEST(NFUN), ABSEST(NFUN) 
EXTERNAL 
FUNSUB 

3 Description
D01EAF uses a globally adaptive method based on the algorithm described by
van Dooren and de Ridder (1976) and
Genz and Malik (1980). It is implemented for integrals in the form:
where
${f}_{i}={f}_{i}\left({x}_{1},{x}_{2},\dots ,{x}_{n}\right)$, for
$i=1,2,\dots ,m$.
Upon entry, unless
MINCLS has been set to a value less than or equal to
$0$, D01EAF divides the integration region into a number of subregions with randomly selected volumes. Inside each subregion the integrals and their errors are estimated. The initial number of subregions is chosen to be as large as possible without using more than
MINCLS calls to
FUNSUB. The results are stored in a partially ordered list (a heap). The routine then proceeds in stages. At each stage the subregion with the largest error (measured using the maximum norm) is halved along the coordinate axis where the integrands have largest absolute fourth differences. The basic rule is applied to each half of this subregion and the results are stored in the list. The results from the two halves are used to update the global integral and error estimates (
FINEST and
ABSEST) and the routine continues unless
$\Vert {\mathbf{ABSEST}}\Vert \le \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ABSREQ}},\Vert {\mathbf{FINEST}}\Vert \times {\mathbf{RELREQ}}\right)$ where the norm
$\Vert .\Vert $ is the maximum norm, or further subdivision would use more than
MAXCLS calls to
FUNSUB. If at some stage there is insufficient working storage to keep the results for the next subdivision, the routine switches to a less efficient mode; only if this mode of operation breaks down is insufficient storage reported.
4 References
Genz A C and Malik A A (1980) An adaptive algorithm for numerical integration over an Ndimensional rectangular region J. Comput. Appl. Math. 6 295–302
van Dooren P and de Ridder L (1976) An adaptive algorithm for numerical integration over an Ndimensional cube J. Comput. Appl. Math. 2 207–217
5 Arguments
 1: $\mathrm{NDIM}$ – INTEGERInput

On entry: $n$, the number of dimensions of the integrals.
Constraint:
${\mathbf{NDIM}}\ge 1$.
 2: $\mathrm{A}\left({\mathbf{NDIM}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the lower limits of integration,
${a}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
 3: $\mathrm{B}\left({\mathbf{NDIM}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the upper limits of integration,
${b}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
 4: $\mathrm{MINCLS}$ – INTEGERInput/Output

On entry: must be set either to the minimum number of
FUNSUB calls to be allowed, in which case
${\mathbf{MINCLS}}\ge 0$ or to a negative value. In this case, the routine continues the calculation started in a previous call with the same integrands and integration limits: no arguments other than
MINCLS,
MAXCLS,
ABSREQ,
RELREQ or
IFAIL must be changed between the calls.
On exit: gives the number of
FUNSUB calls actually used by D01EAF. For the continuation case (
${\mathbf{MINCLS}}<0$ on entry) this is the number of new
FUNSUB calls on the current call to D01EAF.
 5: $\mathrm{MAXCLS}$ – INTEGERInput

On entry: the maximum number of
FUNSUB calls to be allowed. In the continuation case this is the number of new
FUNSUB calls to be allowed.
Constraints:
 ${\mathbf{MAXCLS}}\ge {\mathbf{MINCLS}}$;
 ${\mathbf{MAXCLS}}\ge r$;
 $\text{where}r={2}^{n}+2{n}^{2}+2n+1\text{, if}n<11\text{, or}r=1+n\left(4{n}^{2}6n+14\right)/3\text{, if}n\ge 11$.
 6: $\mathrm{NFUN}$ – INTEGERInput

On entry: $m$, the number of integrands.
Constraint:
${\mathbf{NFUN}}\ge 1$.
 7: $\mathrm{FUNSUB}$ – SUBROUTINE, supplied by the user.External Procedure

FUNSUB must evaluate the integrands
${f}_{i}$ at a given point.
The specification of
FUNSUB is:
INTEGER 
NDIM, NFUN 
REAL (KIND=nag_wp) 
Z(NDIM), F(NFUN) 

 1: $\mathrm{NDIM}$ – INTEGERInput

On entry: $n$, the number of dimensions of the integrals.
 2: $\mathrm{Z}\left({\mathbf{NDIM}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the coordinates of the point at which the integrands must be evaluated.
 3: $\mathrm{NFUN}$ – INTEGERInput

On entry: $m$, the number of integrands.
 4: $\mathrm{F}\left({\mathbf{NFUN}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the value of the $i$th integrand at the given point.
FUNSUB must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D01EAF is called. Arguments denoted as
Input must
not be changed by this procedure.
 8: $\mathrm{ABSREQ}$ – REAL (KIND=nag_wp)Input

On entry: the absolute accuracy required by you.
Constraint:
${\mathbf{ABSREQ}}\ge 0.0$.
 9: $\mathrm{RELREQ}$ – REAL (KIND=nag_wp)Input

On entry: the relative accuracy required by you.
Constraint:
${\mathbf{RELREQ}}\ge 0.0$.
 10: $\mathrm{LENWRK}$ – INTEGERInput

On entry: the dimension of the array
WRKSTR as declared in the (sub)program from which D01EAF is called.
Suggested value:
${\mathbf{LENWRK}}\ge 6n+9m+\left(n+m+2\right)\left(1+p/r\right)$, where
$p$ is the value of
MAXCLS and
$r$ is defined under
MAXCLS. If
LENWRK is significantly smaller than this, the routine will not work as efficiently and may even fail.
Constraint:
${\mathbf{LENWRK}}\ge 8\times {\mathbf{NDIM}}+11\times {\mathbf{NFUN}}+3$.
 11: $\mathrm{WRKSTR}\left({\mathbf{LENWRK}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: if
${\mathbf{MINCLS}}<0$,
WRKSTR must be unchanged from the previous call of D01EAF.
On exit: contains information about the current subdivision which could be used in a continuation call.
 12: $\mathrm{FINEST}\left({\mathbf{NFUN}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{FINEST}}\left(\mathit{i}\right)$ specifies the best estimate obtained from the $\mathit{i}$th integral, for $\mathit{i}=1,2,\dots ,m$.
 13: $\mathrm{ABSEST}\left({\mathbf{NFUN}}\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: ${\mathbf{ABSEST}}\left(\mathit{i}\right)$ specifies the estimated absolute accuracy of ${\mathbf{FINEST}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,m$.
 14: $\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, because for this routine the values of the output arguments may be useful even if
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}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}}=1$

MAXCLS was too small for D01EAF to obtain the required accuracy. The arrays
FINEST and
ABSEST respectively contain current estimates for the integrals and errors.
 ${\mathbf{IFAIL}}=2$

LENWRK is too small for the routine to continue. The arrays
FINEST and
ABSEST respectively contain current estimates for the integrals and errors.
 ${\mathbf{IFAIL}}=3$

On a continuation call,
MAXCLS was set too small to make any progress. Increase
MAXCLS before calling D01EAF again.
 ${\mathbf{IFAIL}}=4$

On entry,  ${\mathbf{NDIM}}<1$, 
or  ${\mathbf{NFUN}}<1$, 
or  ${\mathbf{MAXCLS}}<{\mathbf{MINCLS}}$, 
or  ${\mathbf{MAXCLS}}<r$ (see MAXCLS), 
or  ${\mathbf{ABSREQ}}<0.0$, 
or  ${\mathbf{RELREQ}}<0.0$, 
or  ${\mathbf{LENWRK}}<8\times {\mathbf{NDIM}}+11\times {\mathbf{NFUN}}+3$. 
 ${\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.
7 Accuracy
An absolute error estimate for each integrand is output in the array
ABSEST. The routine exits with
${\mathbf{IFAIL}}={\mathbf{0}}$ if
8 Parallelism and Performance
D01EAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
Usually the running time for D01EAF will be dominated by the time in
FUNSUB, so the maximum time that could be used by D01EAF will be proportional to
MAXCLS multiplied by the cost of a call to
FUNSUB.
On a normal call, you should set ${\mathbf{MINCLS}}=0$ on entry.
For some integrands, particularly those that are poorly behaved in a small part of the integration region, D01EAF may terminate prematurely with values of
ABSEST that are significantly smaller than the actual absolute errors. This behaviour should be suspected if the returned value of
MINCLS is small relative to the expected difficulty of the integrals. When this occurs D01EAF should be called again, but with an entry value of
${\mathbf{MINCLS}}\ge 2r$, (see specification of
MAXCLS) and the results compared with those from the previous call.
If the routine is called with
${\mathbf{MINCLS}}\ge 2r$, the exact values of
FINEST and
ABSEST on return will depend (within statistical limits) on the sequence of random numbers generated internally within D01EAF by calls to
G05SAF. Separate runs will produce identical answers unless the part of the program executed prior to calling D01EAF also calls (directly or indirectly) routines from
Chapter G05, and, in addition, the series of such calls differs between runs.
Because of moderate instability in the application of the basic integration rule, approximately the last $1+{\mathrm{log}}_{10}\left({n}^{3}\right)$ decimal digits may be inaccurate when using D01EAF for large values of $n$.
10 Example
This example computes
where
$j=1,2,\dots ,10$,
${f}_{j}=\mathrm{ln}\left({x}_{1}+2{x}_{2}+3{x}_{3}+4{x}_{4}\right)\mathrm{sin}\left(j+{x}_{1}+2{x}_{2}+3{x}_{3}+4{x}_{4}\right)$. The program is intended to show how to exploit the continuation facility provided with D01EAF: the routine exits with
${\mathbf{IFAIL}}={\mathbf{1}}$ (printing an explanatory error message) and is reentered with
MAXCLS reset to a larger value. The program can be used with any values of
NDIM and
NFUN, except that the expression for
$r$ must be changed if
${\mathbf{NDIM}}>10$ (see specification of
MAXCLS).
10.1 Program Text
Program Text (d01eafe.f90)
10.2 Program Data
None.
10.3 Program Results
Program Results (d01eafe.r)