Settings help

CL Name Style:

## 1Purpose

d01wcc attempts to evaluate a multidimensional integral (up to 15 dimensions), with constant and finite limits,
 $∫ a 1 b 1 ∫ a 2 b 2 ⋯ ∫ a n b n f ( x 1 , x 2 ,…, x n ) dxn ⋯ dx2 dx1$
to a specified relative accuracy, using an adaptive subdivision strategy.

## 2Specification

 #include
void  d01wcc (Integer ndim,
 double (*f)(Integer ndim, const double x[], Nag_User *comm),
const double a[], const double b[], Integer *minpts, Integer maxpts, double eps, double *finval, double *acc, Nag_User *comm, NagError *fail)

## 3Description

d01wcc evaluates an estimate of a multidimensional integral over a hyper-rectangle (i.e., with constant limits), and also an estimate of the relative error. You will need to set the relative accuracy required, supply the integrand as a function f, and also set the minimum and maximum acceptable number of calls to f (in minpts and maxpts).
The function operates by repeated subdivision of the hyper-rectangular region into smaller hyper-rectangles. In each subregion, the integral is estimated using a seventh-degree rule, and an error estimate is obtained by comparison with a fifth-degree rule which uses a subset of the same points. The fourth differences of the integrand along each coordinate axis are evaluated, and the subregion is marked for possible future subdivision in half along that coordinate axis which has the largest absolute fourth difference.
If the estimated errors, totalled over the subregions, exceed the requested relative error (or if fewer than minpts calls to f have been made), further subdivision is necessary, and is performed on the subregion with the largest estimated error, that subregion being halved along the appropriate coordinate axis.
The function will fail if the requested relative error level has not been attained by the time maxpts calls to f have been made.
This function is based on the HALF subroutine developed by van Dooren and de Ridder (1976). It uses a different basic rule, described by Genz and Malik (1980).

## 4References

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

## 5Arguments

1: $\mathbf{ndim}$Integer Input
On entry: the number of dimensions of the integral, $n$.
Constraint: $2\le {\mathbf{ndim}}\le 15$.
2: $\mathbf{f}$function, supplied by the user External Function
f must return the value of the integrand $f$ at a given point.
The specification of f is:
 double f (Integer ndim, const double x[], Nag_User *comm)
1: $\mathbf{ndim}$Integer Input
On entry: the number of dimensions of the integral.
2: $\mathbf{x}\left[{\mathbf{ndim}}\right]$const double Input
On entry: the coordinates of the point at which the integrand must be evaluated.
3: $\mathbf{comm}$Nag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to }\mathbf{p}$ 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 d01wcc. If your code inadvertently does return any NaNs or infinities, d01wcc is likely to produce unexpected results.
3: $\mathbf{a}\left[{\mathbf{ndim}}\right]$const double Input
On entry: the lower limits of integration, ${a}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{b}\left[{\mathbf{ndim}}\right]$const double Input
On entry: the upper limits of integration, ${b}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
5: $\mathbf{minpts}$Integer * Input/Output
On entry: minpts must be set to the minimum number of integrand evaluations to be allowed.
On exit: minpts contains the actual number of integrand evaluations used by this function.
6: $\mathbf{maxpts}$Integer Input
On entry: the maximum number of integrand evaluations to be allowed.
Constraints:
• ${\mathbf{maxpts}}\ge {\mathbf{minpts}}$;
• ${\mathbf{maxpts}}\ge {2}^{{\mathbf{ndim}}}+2×{{\mathbf{ndim}}}^{2}+2×{\mathbf{ndim}}+1$.
7: $\mathbf{eps}$double Input
On entry: the relative error acceptable. When the solution is zero or very small relative accuracy may not be achievable but you may still set eps to a reasonable value and check fail for NE_QUAD_MAX_INTEGRAND_EVAL.
Constraint: ${\mathbf{eps}}>0.0$.
8: $\mathbf{finval}$double * Output
On exit: the best estimate obtained for the integral.
9: $\mathbf{acc}$double * Output
On exit: the estimated relative error in finval.
10: $\mathbf{comm}$Nag_User *
Pointer to a structure of type Nag_User with the following member:
pPointer
On entry/exit: the pointer $\mathbf{comm}\mathbf{\to }\mathbf{p}$, 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 $\mathbf{comm}\mathbf{\to }\mathbf{p}$ by means of a cast to Pointer in the calling program, e.g., comm.p = (Pointer)&s. The type pointer will be void * with a C compiler that defines void * and char * otherwise.
11: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{maxpts}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{minpts}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{maxpts}}\ge {\mathbf{minpts}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INVALID_INT_RANGE_2
Value $⟨\mathit{\text{value}}⟩$ given to ndim not valid. Correct range is $2\le {\mathbf{ndim}}\le 15$.
${\mathbf{maxpts}}<⟨\mathit{\text{value}}⟩$. Constraint: ${\mathbf{maxpts}}\ge {2}^{{\mathbf{ndim}}}+2×{{\mathbf{ndim}}}^{2}+2×{\mathbf{ndim}}+1$.
maxpts was too small to obtain the required accuracy. On return, finval and acc contain estimates of the integral and the relative error, but acc will be greater than eps.
NE_REAL_ARG_LE
On entry, eps must not be less than or equal to 0.0: ${\mathbf{eps}}=⟨\mathit{\text{value}}⟩$.

## 7Accuracy

A relative error estimate is output through the argument acc.

## 8Parallelism and Performance

d01wcc is not threaded in any implementation.

Execution time will usually be dominated by the time taken to evaluate the integrand f, and hence the maximum time that could be taken will be proportional to maxpts.

## 10Example

This example estimates the integral
 $∫ 0 1 ∫ 0 1 ∫ 0 1 ∫ 0 1 4 z 1 z 3 2 exp(2 z 1 z 3 ) (1+ z 2 + z 4 ) 2 dz4 dz3 dz2 dz1 = 0.575364 .$
The accuracy requested is one part in 10,000.

### 10.1Program Text

Program Text (d01wcce.c)

None.

### 10.3Program Results

Program Results (d01wcce.r)