D01 Chapter Contents
D01 Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentD01FBF

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.

1  Purpose

D01FBF computes an estimate of a multidimensional integral (from $1$ to $20$ dimensions), given the analytic form of the integrand and suitable Gaussian weights and abscissae.

2  Specification

 FUNCTION D01FBF ( NDIM, NPTVEC, LWA, WEIGHT, ABSCIS, FUN, IFAIL)
 REAL (KIND=nag_wp) D01FBF
 INTEGER NDIM, NPTVEC(NDIM), LWA, IFAIL REAL (KIND=nag_wp) WEIGHT(LWA), ABSCIS(LWA), FUN EXTERNAL FUN

3  Description

D01FBF approximates a multidimensional integral by evaluating the summation
 $∑i1=1l1 w 1,i1 ∑i2=1l2 w2,i2 ⋯ ∑in=1ln wn,in f x 1 , i1 , x 2 , i2 ,…, x n , in$
given the weights ${w}_{j,{i}_{j}}$ and abscissae ${x}_{j,{i}_{j}}$ for a multidimensional product integration rule (see Davis and Rabinowitz (1975)). The number of dimensions may be anything from $1$ to $20$.
The weights and abscissae for each dimension must have been placed in successive segments of the arrays WEIGHT and ABSCIS; for example, by calling D01BCF or D01TBF once for each dimension using a quadrature formula and number of abscissae appropriate to the range of each ${x}_{j}$ and to the functional dependence of $f$ on ${x}_{j}$.
If normal weights are used, the summation will approximate the integral
 $∫w1x1∫w2x2⋯∫wnxnf x1,x2,…,xn dxn⋯dx2dx1$
where ${w}_{j}\left(x\right)$ is the weight function associated with the quadrature formula chosen for the $j$th dimension; while if adjusted weights are used, the summation will approximate the integral
 $∫∫⋯∫fx1,x2,…,xndxn⋯dx2dx1.$
You must supply a subroutine to evaluate
 $fx1,x2,…,xn$
at any values of ${x}_{1},{x}_{2},\dots ,{x}_{n}$ within the range of integration.

4  References

Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press

5  Parameters

1:     NDIM – INTEGERInput
On entry: $n$, the number of dimensions of the integral.
Constraint: $1\le {\mathbf{NDIM}}\le 20$.
2:     NPTVEC(NDIM) – INTEGER arrayInput
On entry: ${\mathbf{NPTVEC}}\left(\mathit{j}\right)$ must specify the number of points in the $\mathit{j}$th dimension of the summation, for $\mathit{j}=1,2,\dots ,n$.
3:     LWA – INTEGERInput
On entry: the dimension of the arrays WEIGHT and ABSCIS as declared in the (sub)program from which D01FBF is called.
Constraint: ${\mathbf{LWA}}\ge {\mathbf{NPTVEC}}\left(1\right)+{\mathbf{NPTVEC}}\left(2\right)+\cdots +{\mathbf{NPTVEC}}\left({\mathbf{NDIM}}\right)$.
4:     WEIGHT(LWA) – REAL (KIND=nag_wp) arrayInput
On entry: must contain in succession the weights for the various dimensions, i.e., ${\mathbf{WEIGHT}}\left(k\right)$ contains the $i$th weight for the $j$th dimension, with
 $k=NPTVEC1+NPTVEC2+⋯+NPTVECj-1+i.$
5:     ABSCIS(LWA) – REAL (KIND=nag_wp) arrayInput
On entry: must contain in succession the abscissae for the various dimensions, i.e., ${\mathbf{ABSCIS}}\left(k\right)$ contains the $i$th abscissa for the $j$th dimension, with
 $k=NPTVEC1+NPTVEC2+⋯+NPTVECj-1+i.$
6:     FUN – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
FUN must return the value of the integrand $f$ at a specified point.
The specification of FUN is:
 FUNCTION FUN ( NDIM, X)
 REAL (KIND=nag_wp) FUN
 INTEGER NDIM REAL (KIND=nag_wp) X(NDIM)
1:     NDIM – INTEGERInput
On entry: $n$, the number of dimensions of the integral.
2:     X(NDIM) – REAL (KIND=nag_wp) arrayInput
On entry: the coordinates of the point at which the integrand $f$ must be evaluated.
FUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D01FBF is called. Parameters denoted as Input must not be changed by this procedure.
7:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NDIM}}<1$, or ${\mathbf{NDIM}}>20$, or ${\mathbf{LWA}}<{\mathbf{NPTVEC}}\left(1\right)+{\mathbf{NPTVEC}}\left(2\right)+\cdots +{\mathbf{NPTVEC}}\left({\mathbf{NDIM}}\right)$.

7  Accuracy

The accuracy of the computed multidimensional sum depends on the weights and the integrand values at the abscissae. If these numbers vary significantly in size and sign then considerable accuracy could be lost. If these numbers are all positive, then little accuracy will be lost in computing the sum.

The total time taken by D01FBF will be proportional to
 $T×NPTVEC1×NPTVEC2×⋯×NPTVECNDIM,$
where $T$ is the time taken for one evaluation of FUN.

9  Example

This example evaluates the integral
 $∫12∫0∞∫-∞∞∫1∞ x1x2x3 6 x4+2 8e-2x2e-0.5x32dx4dx3dx2dx1$
using adjusted weights. The quadrature formulae chosen are:
• ${x}_{1}$: Gauss–Legendre, $a=1.0$, $b=2.0$,
• ${x}_{2}$: Gauss–Laguerre, $a=0.0$, $b=2.0$,
• ${x}_{3}$: Gauss–Hermite, $a=0.0$, $b=0.5$,
• ${x}_{4}$: rational Gauss, $a=1.0$, $b=2.0$.
Four points are sufficient in each dimension, as this integral is in fact a product of four one-dimensional integrals, for each of which the chosen four-point formula is exact.

9.1  Program Text

Program Text (d01fbfe.f90)

None.

9.3  Program Results

Program Results (d01fbfe.r)