# NAG FL Interfaced01fbf (md_​gauss)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Function d01fbf ( ndim, lwa, f,
 Real (Kind=nag_wp) :: d01fbf Integer, Intent (In) :: ndim, nptvec(ndim), lwa Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), External :: f Real (Kind=nag_wp), Intent (In) :: weight(lwa), abscis(lwa)
#include <nag.h>
 double d01fbf_ (const Integer *ndim, const Integer nptvec[], const Integer *lwa, const double weight[], const double abscis[], double (NAG_CALL *f)(const Integer *ndim, const double x[]),Integer *ifail)
The routine may be called by the names d01fbf or nagf_quad_md_gauss.

## 3Description

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 d01tbf or d01tcf 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
 $∫w1(x1)∫w2(x2)⋯∫wn(xn)f (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
 $∫∫⋯∫f(x1,x2,…,xn)dxn⋯dx2dx1.$
You must supply a subroutine to evaluate
 $f(x1,x2,…,xn)$
at any values of ${x}_{1},{x}_{2},\dots ,{x}_{n}$ within the range of integration.
Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press

## 5Arguments

1: $\mathbf{ndim}$Integer Input
On entry: $n$, the number of dimensions of the integral.
Constraint: $1\le {\mathbf{ndim}}\le 20$.
2: $\mathbf{nptvec}\left({\mathbf{ndim}}\right)$Integer array Input
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: $\mathbf{lwa}$Integer Input
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: $\mathbf{weight}\left({\mathbf{lwa}}\right)$Real (Kind=nag_wp) array Input
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=nptvec(1)+nptvec(2)+⋯+nptvec(j-1)+i.$
5: $\mathbf{abscis}\left({\mathbf{lwa}}\right)$Real (Kind=nag_wp) array Input
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=nptvec(1)+nptvec(2)+⋯+nptvec(j-1)+i.$
6: $\mathbf{f}$real (Kind=nag_wp) Function, supplied by the user. External Procedure
f must return the value of the integrand at a given point.
The specification of f is:
Fortran Interface
 Function f ( ndim, x)
 Real (Kind=nag_wp) :: f Integer, Intent (In) :: ndim Real (Kind=nag_wp), Intent (In) :: x(ndim)
 double f (const Integer *ndim, const double x[])
1: $\mathbf{ndim}$Integer Input
On entry: $n$, the number of dimensions of the integral.
2: $\mathbf{x}\left({\mathbf{ndim}}\right)$Real (Kind=nag_wp) array Input
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 d01fbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01fbf. If your code inadvertently does return any NaNs or infinities, d01fbf is likely to produce unexpected results.
7: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, lwa is too small. ${\mathbf{lwa}}=⟨\mathit{\text{value}}⟩$. Minimum possible dimension: $⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{ndim}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ndim}}\le 20$.
On entry, ${\mathbf{ndim}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ndim}}\ge 1$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

d01fbf is not threaded in any implementation.

The total time taken by d01fbf will be proportional to
 $T×nptvec(1)×nptvec(2)×⋯×nptvec(ndim),$
where $T$ is the time taken for one evaluation of f.

## 10Example

This example evaluates the integral
 $∫12∫0∞∫-∞∞∫1∞ (x1x2x3) 6 (x4+2) 8e-2x2e-0.5x32dx4dx3dx2dx1$
• ${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.

### 10.1Program Text

Program Text (d01fbfe.f90)

None.

### 10.3Program Results

Program Results (d01fbfe.r)