PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_quad_md_sphere_bad (d01ja)
Purpose
nag_quad_md_sphere_bad (d01ja) attempts to evaluate an integral over an -dimensional sphere (, , or ), to a user-specified absolute or relative accuracy, by means of a modified Sag–Szekeres method. The function can handle singularities on the surface or at the centre of the sphere, and returns an error estimate.
Syntax
[
result,
esterr,
nevals,
ifail] = d01ja(
f,
ndim,
radius,
epsa,
epsr,
icoord, 'method',
method)
[
result,
esterr,
nevals,
ifail] = nag_quad_md_sphere_bad(
f,
ndim,
radius,
epsa,
epsr,
icoord, 'method',
method)
Description
nag_quad_md_sphere_bad (d01ja) calculates an approximation to the
-dimensional integral
where
is the hypersphere
(the integrand function may also be defined in spherical coordinates). The algorithm is based on the Sag–Szekeres method (see
Sag and Szekeres (1964)), applying the product trapezoidal formula after a suitable radial transformation. An improved transformation technique is developed: depending on the behaviour of the function and on the required accuracy, different transformations can be used, some of which are ‘double exponential’, as defined by
Takahasi and Mori (1974). The resulting technique allows the function to deal with integrand singularities on the surface or at the centre of the sphere. When the estimated error of the approximation with mesh size
is larger than the tolerated error, the trapezoidal formula with mesh size
is calculated. A drawback of this method is the exponential growth of the number of function evaluations in the successive approximations (this number grows with a factor
). This introduces the restriction
. Because the convergence rate of the successive approximations is normally better than linear, the error estimate is based on the linear extrapolation of the difference between the successive approximations (see
Robinson and de Doncker (1981) and
Roose and de Doncker (1981)). For further details of the algorithm, see
Roose and de Doncker (1981).
References
Robinson I and de Doncker E (1981) Automatic computation of improper integrals over a bounded or unbounded planar region Computing 27 89–284
Roose D and de Doncker E (1981) Automatic integration over a sphere J. Comput. Appl. Math. 7 203–224
Sag T W and Szekeres G (1964) Numerical evaluation of high-dimensional integrals Math. Comput. 18 245–253
Takahasi H and Mori M (1974) Double Exponential Formulas for Numerical Integration 9 Publ. RIMS, Kyoto University 721–741
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. These coordinates are given in Cartesian or spherical polar form according to the value of
icoord.
Output Parameters
- 1:
– double scalar
-
The value of
evaluated at
x.
- 2:
– int64int32nag_int scalar
-
, the dimension of the sphere.
Constraint:
.
- 3:
– double scalar
-
, the radius of the sphere.
Constraint:
.
- 4:
– double scalar
-
The requested absolute tolerance. If
, its absolute value is used. See
Accuracy.
- 5:
– double scalar
-
The requested relative tolerance.
- Its absolute value is used.
- The latter value is used as epsr by the function. See Accuracy.
- 6:
– int64int32nag_int scalar
-
Must specify which kind of coordinates are used in
f.
- Cartesian coordinates
, for .
- Spherical coordinates (see Spherical Polar Coordinates): ;
, for .
- ,
- Special spherical polar coordinates (see Machine Dependencies), with the additional transformation : ;
, for .
Constraint:
,
or
.
If or ,
Optional Input Parameters
- 1:
– int64int32nag_int scalar
Default:
Must specify the transformation to be used by the function. The choice depends on the behaviour of the integrand and on the required accuracy.
For well-behaved functions and functions with mild singularities on the surface of the sphere only:
- Low accuracy required.
- High accuracy required.
For functions with severe singularities on the surface of the sphere only:
- Low accuracy required.
- High accuracy required.
(in this case
icoord must be set to
, and the function defined in special spherical coordinates).
For functions with a singularity at the centre of the sphere (and possibly with singularities on the surface as well):
- Low accuracy required.
- High accuracy required.
can be used as a default value and is equivalent to:
- if , and
- if .
The distinction between low and high required accuracies, as mentioned above, depends also on the behaviour of the function. Roughly one may assume the critical value of
epsa and
epsr to be
, but the critical value will be smaller for a well-behaved integrand and larger for an integrand with severe singularities.
Constraint:
,
,
,
,
,
or
.
If , or
Output Parameters
- 1:
– double scalar
-
The approximation to the integral .
- 2:
– double scalar
-
An estimate of the modulus of the absolute error.
- 3:
– int64int32nag_int scalar
-
The number of function evaluations used.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_quad_md_sphere_bad (d01ja) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
- W
-
The required accuracy cannot be achieved within a limiting number of function evaluations (which is set by the function).
- W
-
The required accuracy cannot be achieved because of round-off error.
- W
-
The required accuracy cannot be achieved because the maximum accuracy with respect to the machine constants
nag_machine_precision (x02aj) and
nag_machine_real_safe (x02am) has been attained. If this maximum accuracy is rather low (compared with
nag_machine_precision (x02aj)), the cause of the problem is a severe singularity on the boundary or at the centre of the sphere. If
,
or
, then setting
or
may help.
-
-
On entry, | or , |
or | , |
or | , , , , , or , |
or | , or , |
or | and or , |
or | or and . |
No calculations have been performed.
result and
esterr are set to
.
-
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
You can specify an absolute and/or a relative tolerance, setting
epsa and
epsr. The function attempts to calculate an approximation
result such that
If
,
esterr returns an estimate of, but not necessarily a bound for,
.
Further Comments
Timing
Timing depends on the integrand and the accuracy required.
Spherical Polar Coordinates
Cartesian coordinates are related to the spherical polar coordinates by:
where
, for
and
.
Machine Dependencies
As a consequence of the transformation technique, the severity of the singularities which can be handled by
nag_quad_md_sphere_bad (d01ja) depends on the precision and range of real numbers on the machine.
or
must be used when the singularity on the surface is ‘severe’ in view of the requested accuracy and
machine precision. In practice one has to set
or
if
nag_quad_md_sphere_bad (d01ja) terminates with
when called with
,
or
.
When integrating a function with a severe singular behaviour on the surface of the sphere, the additional transformation helps to avoid the loss of significant figures due to round-off error in the calculation of the integration nodes which are very close to the surface. For these points, the value of can be computed more accurately than the value of . Naturally, care must be taken that the function subprogram does not contain expressions of the form , which could cause a large round-off error in the calculation of the integrand at the boundary of the sphere.
Care should be taken to avoid underflow and/or overflow problems in the function subprogram, because some of the integration nodes used by nag_quad_md_sphere_bad (d01ja) may be very close to the surface or to the centre of the sphere.
Example:
Note that nag_quad_md_sphere_bad (d01ja) ensures that , but underflow could occur in the computation of .
Example
This example evaluates the integrals
where
, and
is the unit sphere of dimension
.
The exact values (to decimal places) are and .
Open in the MATLAB editor:
d01ja_example
function d01ja_example
fprintf('d01ja example results\n\n');
radius = 1;
epsa = 0;
epsr = 5e-05;
icoord = int64(1);
ndim = int64([2,4]);
for j = 1:2
[result, esterr, nevals, ifail] = ...
d01ja( ...
@f, ndim(j), radius, epsa, epsr, icoord);
fprintf('Dimension of the sphere = %8d\n', ndim(j));
fprintf('Requested relative tolerance = %8.5f\n',epsr);
fprintf('Approximation to the integral = %8.5f\n', result);
fprintf('Number of function evaluations = %8d\n',nevals);
fprintf('Estimated relative error = %8.5f\n\n',esterr);
end
function result = f(ndim, x)
a = (1-x(1))*(1+x(1));
if (a == 0)
result = 0;
else
result = 1/sqrt(a);
end
d01ja example results
Dimension of the sphere = 2
Requested relative tolerance = 0.00005
Approximation to the integral = 6.28319
Number of function evaluations = 193
Estimated relative error = 0.00020
Dimension of the sphere = 4
Requested relative tolerance = 0.00005
Approximation to the integral = 13.16004
Number of function evaluations = 2873
Estimated relative error = 0.00053
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015