PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_quad_md_sphere (d01fd)
Purpose
nag_quad_md_sphere (d01fd) calculates an approximation to a definite integral in up to
dimensions, using the method of Sag and Szekeres (see
Sag and Szekeres (1964)). The region of integration is an
-sphere, or by built-in transformation via the unit
-cube, any product region.
Syntax
[
result,
ncalls,
ifail] = d01fd(
ndim,
f,
sigma,
region,
limit, 'r0',
r0, 'u',
u)
[
result,
ncalls,
ifail] = nag_quad_md_sphere(
ndim,
f,
sigma,
region,
limit, 'r0',
r0, 'u',
u)
Description
nag_quad_md_sphere (d01fd) calculates an approximation to
or, more generally,
where each
and
may be functions of
.
The function uses the method of
Sag and Szekeres (1964), which exploits a property of the shifted
-point trapezoidal rule, namely, that it integrates exactly all polynomials of degree
(see
Krylov (1962)). An attempt is made to induce periodicity in the integrand by making a parameterised transformation to the unit
-sphere. The Jacobian of the transformation and all its direct derivatives vanish rapidly towards the surface of the unit
-sphere, so that, except for functions which have strong singularities on the boundary, the resulting integrand will be pseudo-periodic. In addition, the variation in the integrand can be considerably reduced, causing the trapezoidal rule to perform well.
Integrals of the form
(1) are transformed to the unit
-sphere by the change of variables:
where
and
is an adjustable parameter.
Integrals of the form
(2) are first of all transformed to the
-cube
by a linear change of variables
and then to the unit sphere by a further change of variables
where
and
is again an adjustable parameter.
The parameter in these transformations determines how the transformed integrand is distributed between the origin and the surface of the unit -sphere. A typical value of is . For larger , the integrand is concentrated toward the centre of the unit -sphere, while for smaller it is concentrated toward the perimeter.
In performing the integration over the unit
-sphere by the trapezoidal rule, a displaced equidistant grid of size
is constructed. The points of the mesh lie on concentric layers of radius
The function requires you to specify an approximate maximum number of points to be used, and then computes the largest number of whole layers to be used, subject to an upper limit of
layers.
In practice, the rapidly-decreasing Jacobian makes it unnecessary to include the whole unit -sphere and the integration region is limited by a user-specified cut-off radius . The grid-spacing is determined by and the number of layers to be used. A typical value of is .
Some experimentation may be required with the choice of
(which determines how much of the unit
-sphere is included) and
(which determines how the transformed integrand is distributed between the origin and surface of the unit
-sphere), to obtain best results for particular families of integrals. This matter is discussed further in
Further Comments.
References
Krylov V I (1962) Approximate Calculation of Integrals (trans A H Stroud) Macmillan
Sag T W and Szekeres G (1964) Numerical evaluation of high-dimensional integrals Math. Comput. 18 245–253
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of dimensions of the integral.
Constraint:
.
- 2:
– 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.
- 3:
– double scalar
-
Indicates the region of integration.
- The integration is carried out over the -sphere of radius sigma, centred at the origin.
- The integration is carried out over the product region described by region.
- 4:
– function handle or string containing name of m-file
-
If
,
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 .
If
,
region is not called by
nag_quad_md_sphere (d01fd),
string
'd01fdv'
- 5:
– int64int32nag_int scalar
-
The approximate maximum number of integrand evaluations to be used.
Constraint:
.
Optional Input Parameters
- 1:
– double scalar
Suggested value:
a typical value is
. (See also
Further Comments.)
Default:
The cut-off radius on the unit -sphere, which may be regarded as an adjustable parameter of the method.
Constraint:
.
- 2:
– double scalar
Suggested value:
a typical value is
. (See also
Further Comments.)
Default:
Must specify an adjustable parameter of the transformation to the unit -sphere.
Constraint:
.
Output Parameters
- 1:
– double scalar
-
The approximation to the integral .
- 2:
– int64int32nag_int scalar
-
The actual number of integrand evaluations used. (See also
Further Comments.)
- 3:
– 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 | . |
-
-
-
-
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
No error estimate is returned, but results may be verified by repeating with an increased value of
limit (provided that this causes an increase in the returned value of
ncalls).
Further Comments
The time taken by
nag_quad_md_sphere (d01fd) will be approximately proportional to the returned value of
ncalls, which, except in the circumstances outlined in
(b) below, will be close to the given value of
limit.
(a) |
Choice of and If the chosen combination of and is too large in relation to the machine accuracy it is possible that some of the points generated in the original region of integration may transform into points in the unit -sphere which lie too close to the boundary surface to be distinguished from it to machine accuracy (despite the fact that ). To be specific, the combination of and is too large if
or
where is the number of bits in the mantissa of a double number.
The contribution of such points to the integral is neglected. This may be justified by appeal to the fact that the Jacobian of the transformation rapidly approaches zero towards the surface. Neglect of these points avoids the occurrence of overflow with integrands which are infinite on the boundary. |
(b) |
Values of limit and ncalls
limit is an approximate upper limit to the number of integrand evaluations, and may not be chosen less than . There are two circumstances when the returned value of ncalls (the actual number of evaluations used) may be significantly less than limit.
Firstly, as explained in (a), an unsuitably large combination of and may result in some of the points being unusable. Such points are not included in the returned value of ncalls.
Secondly, no more than layers will ever be used, no matter how high limit is set. This places an effective upper limit on ncalls as follows:
|
Example
This example calculates the integral
where
is the
-sphere of radius
,
and
. Both sphere-to-sphere and general product region transformations are used. For the former, we use
and
; for the latter,
and
.
Open in the MATLAB editor:
d01fd_example
function d01fd_example
fprintf('d01fd example results\n\n');
ndim = int64(3);
sigma = 1.5;
limit = int64(8000);
r0 = 0.9;
[result, ncalls, ifail] = ...
d01fd(...
ndim, @f, sigma, @region, limit, 'r0', r0);
fprintf('Sphere-to-sphere transformation\n\n');
fprintf('Estimated value of the integral = %9.3f\n', result);
fprintf('Number of integrand evaluations = %5d\n\n', ncalls);
sigma = -1;
r0 = 0.8;
[result, ncalls, ifail] = ...
d01fd(...
ndim, @f, sigma, @region, limit, 'r0', r0);
fprintf('Product region transformation\n\n');
fprintf('Estimated value of the integral = %9.3f\n', result);
fprintf('Number of integrand evaluations = %5d\n', ncalls);
function result = f(ndim,x)
result=1/sqrt(abs(9/4 - dot(x,x)));
function [c,d] = region(ndim, x, j)
d = sqrt(abs(9/4-dot(x(1:j-1),x(1:j-1))));
c = -d;
d01fd example results
Sphere-to-sphere transformation
Estimated value of the integral = 22.168
Number of integrand evaluations = 8026
Product region transformation
Estimated value of the integral = 22.137
Number of integrand evaluations = 8026
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015