D01FDF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D01FDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

D01FDF calculates an approximation to a definite integral in up to 30 dimensions, using the method of Sag and Szekeres (see Sag and Szekeres (1964)). The region of integration is an n-sphere, or by built-in transformation via the unit n-cube, any product region.

2  Specification

SUBROUTINE D01FDF ( NDIM, F, SIGMA, REGION, LIMIT, R0, U, RESULT, NCALLS, IFAIL)
INTEGER  NDIM, LIMIT, NCALLS, IFAIL
REAL (KIND=nag_wp)  F, SIGMA, R0, U, RESULT
EXTERNAL  F, REGION

3  Description

D01FDF calculates an approximation to
n-sphere of radius  σ f x1,x2,,xn dx1 dx2 dxn (1)
or, more generally,
c1 d1 dx1 cn dn dxn f x1,,xn (2)
where each ci and di may be functions of xj j<i.
The routine uses the method of Sag and Szekeres (1964), which exploits a property of the shifted p-point trapezoidal rule, namely, that it integrates exactly all polynomials of degree <p (see Krylov (1962)). An attempt is made to induce periodicity in the integrand by making a parameterised transformation to the unit n-sphere. The Jacobian of the transformation and all its direct derivatives vanish rapidly towards the surface of the unit n-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 n-sphere by the change of variables:
xi = yi σr tanh ur 1-r2  
where r2=i=1nyi2 and u is an adjustable parameter.
Integrals of the form (2) are first of all transformed to the n-cube -1,1n by a linear change of variables
xi=di+ci+di-ciyi/2  
and then to the unit sphere by a further change of variables
yi=tanhuzi 1-r  
where r2=i=1nzi2 and u is again an adjustable parameter.
The parameter u in these transformations determines how the transformed integrand is distributed between the origin and the surface of the unit n-sphere. A typical value of u is 1.5. For larger u, the integrand is concentrated toward the centre of the unit n-sphere, while for smaller u it is concentrated toward the perimeter.
In performing the integration over the unit n-sphere by the trapezoidal rule, a displaced equidistant grid of size h is constructed. The points of the mesh lie on concentric layers of radius
ri=h4n+8i-1,  i=1,2,3,.  
The routine 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 400 layers.
In practice, the rapidly-decreasing Jacobian makes it unnecessary to include the whole unit n-sphere and the integration region is limited by a user-specified cut-off radius r0<1. The grid-spacing h is determined by r0 and the number of layers to be used. A typical value of r0 is 0.8.
Some experimentation may be required with the choice of r0 (which determines how much of the unit n-sphere is included) and u (which determines how the transformed integrand is distributed between the origin and surface of the unit n-sphere), to obtain best results for particular families of integrals. This matter is discussed further in Section 9.

4  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

5  Parameters

1:     NDIM – INTEGERInput
On entry: n, the number of dimensions of the integral.
Constraint: 1NDIM30.
2:     F – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
F must return the value of the integrand f at a given point.
The specification of F is:
FUNCTION F ( NDIM, X)
REAL (KIND=nag_wp) F
INTEGER  NDIM
REAL (KIND=nag_wp)  X(NDIM)
1:     NDIM – INTEGERInput
On entry: n, the number of dimensions of the integral.
2:     XNDIM – REAL (KIND=nag_wp) arrayInput
On entry: the coordinates of the point at which the integrand f must be evaluated.
F must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D01FDF is called. Parameters denoted as Input must not be changed by this procedure.
3:     SIGMA – REAL (KIND=nag_wp)Input
On entry: indicates the region of integration.
SIGMA0.0
The integration is carried out over the n-sphere of radius SIGMA, centred at the origin.
SIGMA<0.0
The integration is carried out over the product region described by REGION.
4:     REGION – SUBROUTINE, supplied by the NAG Library or the user.External Procedure
If SIGMA<0.0, REGION must evaluate the limits of integration in any dimension.
The specification of REGION is:
SUBROUTINE REGION ( NDIM, X, J, C, D)
INTEGER  NDIM, J
REAL (KIND=nag_wp)  X(NDIM), C, D
1:     NDIM – INTEGERInput
On entry: n, the number of dimensions of the integral.
2:     XNDIM – REAL (KIND=nag_wp) arrayInput
On entry: X1,,Xj-1 contain the current values of the first j-1 variables, which may be used if necessary in calculating cj and dj.
3:     J – INTEGERInput
On entry: the index j for which the limits of the range of integration are required.
4:     C – REAL (KIND=nag_wp)Output
On exit: the lower limit cj of the range of xj.
5:     D – REAL (KIND=nag_wp)Output
On exit: the upper limit dj of the range of xj.
REGION must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D01FDF is called. Parameters denoted as Input must not be changed by this procedure.
If SIGMA0.0, REGION is not called by D01FDF, but a dummy routine must be supplied (D01FDV may be used).
5:     LIMIT – INTEGERInput
On entry: the approximate maximum number of integrand evaluations to be used.
Constraint: LIMIT100.
6:     R0 – REAL (KIND=nag_wp)Input
On entry: the cut-off radius on the unit n-sphere, which may be regarded as an adjustable parameter of the method.
Suggested value: a typical value is R0=0.8. (See also Section 9.)
Constraint: 0.0<R0<1.0.
7:     U – REAL (KIND=nag_wp)Input
On entry: must specify an adjustable parameter of the transformation to the unit n-sphere.
Suggested value: a typical value is U=1.5. (See also Section 9.)
Constraint: U>0.0.
8:     RESULT – REAL (KIND=nag_wp)Output
On exit: the approximation to the integral I.
9:     NCALLS – INTEGEROutput
On exit: the actual number of integrand evaluations used. (See also Section 9.)
10:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,NDIM<1,
orNDIM>30.
IFAIL=2
On entry,LIMIT<100.
IFAIL=3
On entry,R00.0,
orR01.0.
IFAIL=4
On entry,U0.0.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  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).

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by D01FDF 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 r0 and u 
If the chosen combination of r0 and u 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 n-sphere which lie too close to the boundary surface to be distinguished from it to machine accuracy (despite the fact that r0<1). To be specific, the combination of r0 and u is too large if
ur0 1-r02 >0.3465t-1,   if ​SIGMA0.0,  
or
ur0 1-r0 > 0.3465t- 1,   if ​ SIGMA< 0.0,  
where t is the number of bits in the mantissa of a real 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 100. 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 r0 and u may result in some of the points being unusable. Such points are not included in the returned value of NCALLS.
Secondly, no more than 400 layers will ever be used, no matter how high LIMIT is set. This places an effective upper limit on NCALLS as follows:
n=1: 56 n=2: 1252 n=3: 23690 n=4: 394528 n=5: 5956906  

10  Example

This example calculates the integral
s dx1dx2dx3 σ2-r2 =22.2066  
where s is the 3-sphere of radius σ, r2=x12+x22+x32 and σ=1.5. Both sphere-to-sphere and general product region transformations are used. For the former, we use r0=0.9 and u=1.5; for the latter, r0=0.8 and u=1.5.

10.1  Program Text

Program Text (d01fdfe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (d01fdfe.r)


D01FDF (PDF version)
D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015