D01EAF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D01EAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

D01EAF computes approximations to the integrals of a vector of similar functions, each defined over the same multidimensional hyper-rectangular 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:
a1b1a2b2anbnf1,f2,,fmdxndx2dx1,  
where fi=fix1,x2,,xn, for i=1,2,,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 ABSESTmaxABSREQ,FINEST×RELREQ where the norm . 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 N-dimensional 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 N-dimensional cube J. Comput. Appl. Math. 2 207–217

5  Parameters

1:     NDIM – INTEGERInput
On entry: n, the number of dimensions of the integrals.
Constraint: NDIM1.
2:     ANDIM – REAL (KIND=nag_wp) arrayInput
On entry: the lower limits of integration, ai, for i=1,2,,n.
3:     BNDIM – REAL (KIND=nag_wp) arrayInput
On entry: the upper limits of integration, bi, for i=1,2,,n.
4:     MINCLS – INTEGERInput/Output
On entry: must be set either to the minimum number of FUNSUB calls to be allowed, in which case MINCLS0 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 parameters 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 (MINCLS<0 on entry) this is the number of new FUNSUB calls on the current call to D01EAF.
5:     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:
  • MAXCLSMINCLS;
  • MAXCLSr;
  • where ​r=2n+2n2+2n+1, if ​n<11, or ​r=1+n4n2-6n+14/3, if ​n11.
6:     NFUN – INTEGERInput
On entry: m, the number of integrands.
Constraint: NFUN1.
7:     FUNSUB – SUBROUTINE, supplied by the user.External Procedure
FUNSUB must evaluate the integrands fi at a given point.
The specification of FUNSUB is:
SUBROUTINE FUNSUB ( NDIM, Z, NFUN, F)
INTEGER  NDIM, NFUN
REAL (KIND=nag_wp)  Z(NDIM), F(NFUN)
1:     NDIM – INTEGERInput
On entry: n, the number of dimensions of the integrals.
2:     ZNDIM – REAL (KIND=nag_wp) arrayInput
On entry: the coordinates of the point at which the integrands must be evaluated.
3:     NFUN – INTEGERInput
On entry: m, the number of integrands.
4:     FNFUN – REAL (KIND=nag_wp) arrayOutput
On exit: the value of the ith 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. Parameters denoted as Input must not be changed by this procedure.
8:     ABSREQ – REAL (KIND=nag_wp)Input
On entry: the absolute accuracy required by you.
Constraint: ABSREQ0.0.
9:     RELREQ – REAL (KIND=nag_wp)Input
On entry: the relative accuracy required by you.
Constraint: RELREQ0.0.
10:   LENWRK – INTEGERInput
On entry: the dimension of the array WRKSTR as declared in the (sub)program from which D01EAF is called.
Suggested value: LENWRK6n+9m+n+m+21+p/r, 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: LENWRK8×NDIM+11×NFUN+3.
11:   WRKSTRLENWRK – REAL (KIND=nag_wp) arrayInput/Output
On entry: if 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:   FINESTNFUN – REAL (KIND=nag_wp) arrayOutput
On exit: FINESTi specifies the best estimate obtained from the ith integral, for i=1,2,,m.
13:   ABSESTNFUN – REAL (KIND=nag_wp) arrayOutput
On exit: ABSESTi specifies the estimated absolute accuracy of FINESTi, for i=1,2,,m.
14:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
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.
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.
IFAIL=3
On a continuation call, MAXCLS was set too small to make any progress. Increase MAXCLS before calling D01EAF again.
IFAIL=4
On entry,NDIM<1,
orNFUN<1,
orMAXCLS<MINCLS,
orMAXCLS<r (see MAXCLS),
orABSREQ<0.0,
orRELREQ<0.0,
orLENWRK<8×NDIM+11×NFUN+3.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

An absolute error estimate for each integrand is output in the array ABSEST. The routine exits with IFAIL=0 if
maxiABSESTimaxABSREQ,RELREQ×maxiFINESTi.  

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 implementation-specific information.

9  Further Comments

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 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 MINCLS2r, (see specification of MAXCLS) and the results compared with those from the previous call.
If the routine is called with MINCLS2r, 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+ log10n3  decimal digits may be inaccurate when using D01EAF for large values of n.

10  Example

This example computes
01 01 01 01 f1,f2,,f10 dx4 dx3 dx2 dx1 ,  
where j=1,2,,10, fj=lnx1+2x2+3x3+4x4sinj+x1+2x2+3x3+4x4. The program is intended to show how to exploit the continuation facility provided with D01EAF: the routine exits with IFAIL=1 (printing an explanatory error message) and is re-entered 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 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)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −0.4 −0.2 0 0.2 0.4 0 2 4 6 8 10 12 Integral Values Integrand Number Example Program Multi-dimensional Integrals of 10 Integrands with Various Numbers of Function Calls gnuplot_plot_1 57 calls gnuplot_plot_2 798 calls gnuplot_plot_3 912 calls
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0.0001 0.001 0.01 0.1 0 2 4 6 8 10 12 Estimated Error Integrand Number Errors in Computing Integrals of 10 Integrands with Various Numbers of Function Calls gnuplot_plot_1 57 calls gnuplot_plot_2 798 calls gnuplot_plot_3 912 calls

D01EAF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

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