PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_quad_md_numth (d01gc)
Purpose
nag_quad_md_numth (d01gc) calculates an approximation to a definite integral in up to dimensions, using the Korobov–Conroy number theoretic method.
Syntax
[
vk,
res,
err,
ifail] = d01gc(
f,
region,
npts,
vk,
nrand, 'ndim',
ndim, 'itrans',
itrans)
[
vk,
res,
err,
ifail] = nag_quad_md_numth(
f,
region,
npts,
vk,
nrand, 'ndim',
ndim, 'itrans',
itrans)
Description
nag_quad_md_numth (d01gc) calculates an approximation to the integral
using the Korobov–Conroy number theoretic method (see
Korobov (1957),
Korobov (1963) and
Conroy (1967)). The region of integration defined in
(1) is such that generally
and
may be functions of
, for
, with
and
constants. The integral is first of all transformed to an integral over the
-cube
by the change of variables
The method then uses as its basis the number theoretic formula for the
-cube,
:
where
denotes the fractional part of
,
are the so-called optimal coefficients,
is the error, and
is a prime integer. (It is strictly only necessary that
be relatively prime to all
and is in fact chosen to be even for some cases in
Conroy (1967).) The method makes use of properties of the Fourier expansion of
which is assumed to have some degree of periodicity. Depending on the choice of
the contributions from certain groups of Fourier coefficients are eliminated from the error,
. Korobov shows that
can be chosen so that the error satisfies
where
and
are real numbers depending on the convergence rate of the Fourier series,
is a constant depending on
, and
is a constant depending on
and
. There are a number of procedures for calculating these optimal coefficients. Korobov imposes the constraint that
and gives a procedure for calculating the argument,
, to satisfy the optimal conditions.
In this function the periodisation is achieved by the simple transformation
More sophisticated periodisation procedures are available but in practice the degree of periodisation does not appear to be a critical requirement of the method.
An easily calculable error estimate is not available apart from repetition with an increasing sequence of values of
which can yield erratic results. The difficulties have been studied by
Cranley and Patterson (1976) who have proposed a Monte–Carlo error estimate arising from converting
(2) into a stochastic integration rule by the inclusion of a random origin shift which leaves the form of the error
(3) unchanged; i.e., in the formula
(2),
is replaced by
, for
, where each
, is uniformly distributed over
. Computing the integral for each of a sequence of random vectors
allows a ‘standard error’ to be estimated.
This function provides built-in sets of optimal coefficients, corresponding to six different values of
. Alternatively, the optimal coefficients may be supplied by you. Functions
nag_quad_md_numth_coeff_prime (d01gy) and
nag_quad_md_numth_coeff_2prime (d01gz) compute the optimal coefficients for the cases where
is a prime number or
is a product of two primes, respectively.
References
Conroy H (1967) Molecular Shroedinger equation VIII. A new method for evaluting multi-dimensional integrals J. Chem. Phys. 47 5307–5318
Cranley R and Patterson T N L (1976) Randomisation of number theoretic methods for mulitple integration SIAM J. Numer. Anal. 13 904–914
Korobov N M (1957) The approximate calculation of multiple integrals using number theoretic methods Dokl. Acad. Nauk SSSR 115 1062–1065
Korobov N M (1963) Number Theoretic Methods in Approximate Analysis Fizmatgiz, Moscow
Parameters
Compulsory Input Parameters
- 1:
– function handle or string containing name of m-file
-
f must return the value of the integrand
at a given point.
[result] = f(ndim, x)
Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of dimensions of the integral.
- 2:
– double array
-
The coordinates of the point at which the integrand must be evaluated.
Output Parameters
- 1:
– double scalar
-
The value of
evaluated at
x.
- 2:
– function handle or string containing name of m-file
-
region must evaluate the limits of integration in any dimension.
[c, d] = region(ndim, x, j)
Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of dimensions of the integral.
- 2:
– double array
-
contain the current values of the first variables, which may be used if necessary in calculating and .
- 3:
– int64int32nag_int scalar
-
The index for which the limits of the range of integration are required.
Output Parameters
- 1:
– double scalar
-
The lower limit of the range of .
- 2:
– double scalar
-
The upper limit of the range of .
- 3:
– int64int32nag_int scalar
-
The Korobov rule to be used. There are two alternatives depending on the value of
npts.
(i) |
.
In this case one of six preset rules is chosen using , , , , or points depending on the respective value of npts being , , , , or . |
(ii) |
.
npts is the number of actual points to be used with corresponding optimal coefficients supplied in the array vk. |
Constraint:
.
- 4:
– double array
-
If
,
vk must contain the
optimal coefficients (which may be calculated using
nag_quad_md_numth_coeff_prime (d01gy) or
nag_quad_md_numth_coeff_2prime (d01gz)).
If
,
vk need not be set.
- 5:
– int64int32nag_int scalar
-
The number of random samples to be generated in the error estimation (generally a small value, say to , is sufficient). The total number of integrand evaluations will be .
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
vk.
, the number of dimensions of the integral.
Constraint:
.
- 2:
– int64int32nag_int scalar
Default:
Indicates whether the periodising transformation is to be used.
- The transformation is to be used.
- The transformation is to be suppressed (to cover cases where the integrand may already be periodic or where you want to specify a particular transformation in the definition of f).
Output Parameters
- 1:
– double array
-
If
,
vk is unchanged.
If
,
vk contains the
optimal coefficients used by the preset rule.
- 2:
– double scalar
-
The approximation to the integral .
- 3:
– double scalar
-
The standard error as computed from
nrand sample values. If
, then
err contains zero.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | . |
-
-
-
-
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
An estimate of the absolute standard error is given by the value, on exit, of
err.
Further Comments
The time taken by nag_quad_md_numth (d01gc) will be approximately proportional to , where is the number of points used.
The exact values of
res and
err on return will depend (within statistical limits) on the sequence of random numbers generated within
nag_quad_md_numth (d01gc) by calls to
nag_rand_dist_uniform01 (g05sa). Separate runs will produce identical answers.
Example
This example calculates the integral
Open in the MATLAB editor:
d01gc_example
function d01gc_example
fprintf('d01gc example results\n\n');
npts = int64(2);
vk = zeros(4,1);
nrand = int64(4);
[vk, res, err, ifail] = d01gc( ...
@f, @region, npts, vk, nrand);
fprintf('Result = %13.5f, Standard error = %10.2e\n', res, err);
function result = f(ndim,x)
result = cos(0.5+2*sum(x)-double(ndim));
function [c,d] = region(ndim, x, j)
c=0;
d=1;
d01gc example results
Result = 0.43999, Standard error = 1.89e-06
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015