d01gbf uses an adaptive Monte–Carlo method based on the algorithm described in
Lautrup (1971). It is implemented for integrals of the form:
Upon entry, unless
lenwrk has been set to the minimum value
, the routine subdivides the integration region into a number of equal volume subregions. Inside each subregion the integral and the variance are estimated by means of pseudorandom sampling. All contributions are added together to produce an estimate for the whole integral and total variance. The variance along each coordinate axis is determined and the routine uses this information to increase the density and change the widths of the sub-intervals along each axis, so as to reduce the total variance. The total number of subregions is then increased by a factor of two and the program recycles for another iteration. The program stops when a desired accuracy has been reached or too many integral evaluations are needed for the next cycle.
- 1: – IntegerInput
-
On entry: , the number of dimensions of the integral.
Constraint:
.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the lower limits of integration,
, for .
- 3: – Real (Kind=nag_wp) arrayInput
-
On entry: the upper limits of integration,
, for .
- 4: – IntegerInput/Output
-
On entry: must be set
- either to the minimum number of integrand evaluations to be allowed, in which case ;
- or to a negative value. In this case, the routine assumes that a previous call had been made with the same arguments ndim, a and b and with either the same integrand (in which case d01gbf continues calculation) or a similar integrand (in which case d01gbf begins the calculation with the subdivision used in the last iteration of the previous call). See also wrkstr.
On exit: contains the number of integrand evaluations actually used by d01gbf.
- 5: – IntegerInput
-
On entry: the maximum number of integrand evaluations to be allowed. In the continuation case this is the number of new integrand evaluations to be allowed. These counts do not include zero integrand values.
Constraints:
- ;
- .
- 6: – real (Kind=nag_wp) Function, supplied by the user.External Procedure
-
functn must return the value of the integrand
at a given point.
The specification of
functn is:
Fortran Interface
Function functn ( |
ndim, x) |
Real (Kind=nag_wp) | :: | functn | Integer, Intent (In) | :: | ndim | Real (Kind=nag_wp), Intent (In) | :: | x(ndim) |
|
C Header Interface
#include <nagmk26.h>
double |
functn (const Integer *ndim, const double x[]) |
|
- 1: – IntegerInput
-
On entry: , the number of dimensions of the integral.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the coordinates of the point at which the integrand must be evaluated.
functn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d01gbf is called. Arguments denoted as
Input must
not be changed by this procedure.
Note: functn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
d01gbf. If your code inadvertently
does return any NaNs or infinities,
d01gbf is likely to produce unexpected results.
- 7: – Real (Kind=nag_wp)Input
-
On entry: the relative accuracy required.
Constraint:
.
- 8: – Real (Kind=nag_wp)Output
-
On exit: the estimated relative accuracy of
finest.
- 9: – IntegerInput
-
On entry: the dimension of the array
wrkstr as declared in the (sub)program from which
d01gbf is called.
For maximum efficiency,
lenwrk should be about
If
lenwrk is given the value
then the subroutine uses only one iteration of a crude Monte–Carlo method with
maxcls sample points.
Constraint:
.
- 10: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: if
,
wrkstr must be unchanged from the previous call of
d01gbf – except that for a new integrand
must be set to
. See also
mincls.
On exit: contains information about the current sub-interval structure which could be used in later calls of d01gbf. In particular, gives the number of sub-intervals used along the th coordinate axis.
- 11: – Real (Kind=nag_wp)Input/Output
-
On entry: must be unchanged from a previous call to d01gbf.
On exit: the best estimate obtained for the integral.
- 12: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
A relative error estimate is output through the argument
acc. The confidence factor is set so that the actual error should be less than
acc 90% of the time. If you want a higher confidence level then a smaller value of
eps should be used.
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.
The running time for
d01gbf will usually be dominated by the time used to evaluate the integrand
, so the maximum time that could be used is approximately proportional to
maxcls.
For some integrands, particularly those that are poorly behaved in a small part of the integration region,
d01gbf may terminate with a value of
acc which is significantly smaller than the actual relative error. This should be suspected if the returned value of
mincls is small relative to the expected difficulty of the integral. Where this occurs,
d01gbf should be called again, but with a higher entry value of
mincls (e.g., twice the returned value) and the results compared with those from the previous call.
The exact values of
finest and
acc on return will depend (within statistical limits) on the sequence of random numbers generated within this routine.
This example calculates the integral
None.