d01xbc evaluates an approximation to the integral of a function over a hyper-rectangular region, using a Monte–Carlo method. An approximate relative error estimate is also returned. This function is suitable for low accuracy work.
The function may be called by the names: d01xbc, nag_quad_multid_quad_monte_carlo_1 or nag_multid_quad_monte_carlo_1.
3Description
d01xbc uses an adaptive Monte–Carlo method based on the algorithm described by Lautrup (1971). It is implemented for integrals of the form:
Upon entry, unless the argument , the function 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 function 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.
4References
Lautrup B (1971) An adaptive multi-dimensional integration procedure Proc. 2nd Coll. Advanced Methods in Theoretical Physics, Marseille
5Arguments
1: – IntegerInput
On entry: the number of dimensions of the integral, .
Constraint:
.
2: – function, supplied by the userExternal Function
f must return the value of the integrand at a given point.
On entry: the number of dimensions of the integral.
2: – const doubleInput
On entry: the coordinates of the point at which the integrand must be evaluated.
3: – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer should be cast to the required type, e.g.,
struct user *s = (struct user *)comm → p, to obtain the original object's address with appropriate type. (See the argument comm below.)
Note:f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01xbc. If your code inadvertently does return any NaNs or infinities, d01xbc is likely to produce unexpected results.
3: – Nag_MCMethodInput
On entry: the method to be used.
The function uses only one iteration of a crude Monte–Carlo method with maxcls sample points.
The function subdivides the integration region into a number of equal volume subregions.
Constraint:
or .
4: – Nag_StartInput
On entry: the continuation state of the evaluation of the integrand.
Indicates that this is the first call to the function with the current integrand and arguments ndim, a and b.
Indicates that a previous call has been made with the same arguments ndim, a and b with the same integrand. Please note that method must not be changed.
Indicates that a previous call has been made with the same arguments ndim, a and b but that the integrand is new. Please note that method must not be changed.
Constraint:
, or .
5: – const doubleInput
On entry: the lower limits of integration, , for .
6: – const doubleInput
On entry: the upper limits of integration, , for .
7: – Integer *Input/Output
On entry: mincls must be set to the minimum number of integrand evaluations to be allowed.
Constraint:
.
On exit: mincls contains the total number of integrand evaluations actually used by d01xbc.
8: – 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:
;
.
9: – doubleInput
On entry: the relative accuracy required.
Constraint:
.
10: – double *Output
On exit: the best estimate obtained for the integral.
11: – double *Output
On exit: the estimated relative accuracy of finest.
12: – double **Input/Output
On entry: if or , the memory pointed to and allocated by a previous call of d01xbc must be unchanged.
If then appropriate memory is allocated internally by d01xbc.
On exit: comm_arr contains information about the current sub-interval structure which could be used in later calls of d01xbc. In particular, gives the number of sub-intervals used along the th coordinate axis.
When this information is no longer useful, or before a subsequent call to d01xbc with is made, you should free the storage contained in this pointer using the NAG macro NAG_FREE. Note this memory will have been allocated and needs to be freed only if the error exit NE_NOERROR or NE_QUAD_MAX_INTEGRAND_EVAL occurs. Otherwise, no memory needs to be freed.
13: – Nag_User *
Pointer to a structure of type Nag_User with the following member:
p – Pointer
On entry/exit: the pointer , of type Pointer, allows you to communicate information to and from f(). An object of the required type should be declared, e.g., a structure, and its address assigned to the pointer by means of a cast to Pointer in the calling program, e.g., comm.p = (Pointer)&s. The type Pointer is void *.
14: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
maxcls was too small to obtain the required accuracy.
In this case d01xbc returns a value of finest with estimated relative error acc, but acc will be greater than eps. This error exit may be taken before maxcls nonzero integrand evaluations have actually occurred, if the function calculates that the current estimates could not be improved before maxcls was exceeded.
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 % of the time. If you desire a higher confidence level then a smaller value of eps should be used.
8Parallelism and Performance
d01xbc is not threaded in any implementation.
9Further Comments
The running time for d01xbc will usually be dominated by the time used to evaluate the integrand f, 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, this function 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, d01xbc 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.
9.1Additional Information
The exact values of finest and acc on return will depend (within statistical limits) on the sequence of random numbers generated within this function.
If desired, you may ensure the identity or difference between runs of the results returned by this function by calling g05cbc or g05ccc immediately prior to calling this function.
where seed is a scalar value used to initialize the underlying random number generator. Using the same value for seed will ensure that the same sequence of random values are generated and hence that the same result from this function will be obtained.
Each time g05ccc is called the underlying random number generator will be reinitialized using a random seed, ensuring a different sequence of values being used. Consequently this function may return different numerical results.