nag_quad_md_gauss (d01fbc) (PDF version)
d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

NAG Library Function Documentnag_quad_md_gauss (d01fbc)

1  Purpose

nag_quad_md_gauss (d01fbc) 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

 #include #include
double  nag_quad_md_gauss (Integer ndim, const Integer nptvec[], Integer lwa, const double weight[], const double abscis[],
 double (*fun)(Integer ndim, const double x[], Nag_Comm *comm),
Nag_Comm *comm, NagError *fail)

3  Description

nag_quad_md_gauss (d01fbc) 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 nag_quad_1d_gauss_wset (d01tbc) or nag_quad_1d_gauss_wgen (d01tcc) 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 function 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  Arguments

1:     ndimIntegerInput
On entry: $n$, the number of dimensions of the integral.
Constraint: $1\le {\mathbf{ndim}}\le 20$.
2:     nptvec[ndim]const IntegerInput
On entry: ${\mathbf{nptvec}}\left[\mathit{j}-1\right]$ must specify the number of points in the $\mathit{j}$th dimension of the summation, for $\mathit{j}=1,2,\dots ,n$.
3:     lwaIntegerInput
On entry: the dimension of the arrays weight and abscis.
Constraint: ${\mathbf{lwa}}\ge {\mathbf{nptvec}}\left[0\right]+{\mathbf{nptvec}}\left[1\right]+\cdots +{\mathbf{nptvec}}\left[{\mathbf{ndim}}-1\right]$.
4:     weight[lwa]const doubleInput
On entry: must contain in succession the weights for the various dimensions, i.e., ${\mathbf{weight}}\left[k-1\right]$ contains the $i$th weight for the $j$th dimension, with
 $k=nptvec[0]+nptvec[1]+⋯+nptvec[j-2]+i.$
5:     abscis[lwa]const doubleInput
On entry: must contain in succession the abscissae for the various dimensions, i.e., ${\mathbf{abscis}}\left[k-1\right]$ contains the $i$th abscissa for the $j$th dimension, with
 $k=nptvec[0]+nptvec[1]+⋯+nptvec[j-2]+i.$
6:     funfunction, supplied by the userExternal Function
fun must return the value of the integrand $f$ at a specified point.
The specification of fun is:
 double fun (Integer ndim, const double x[], Nag_Comm *comm)
1:     ndimIntegerInput
On entry: $n$, the number of dimensions of the integral.
2:     x[ndim]const doubleInput
On entry: the coordinates of the point at which the integrand $f$ must be evaluated.
3:     commNag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to fun.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling nag_quad_md_gauss (d01fbc) you may allocate memory and initialize these pointers with various quantities for use by fun when called from nag_quad_md_gauss (d01fbc) (see Section 3.2.1 in the Essential Introduction).
7:     commNag_Comm *Communication Structure
The NAG communication argument (see Section 3.2.1.1 in the Essential Introduction).
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ndim}}\le 20$.
On entry, ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ndim}}\ge 1$.
NE_INT_2
On entry, lwa is too small. ${\mathbf{lwa}}=〈\mathit{\text{value}}〉$. Minimum possible dimension: $〈\mathit{\text{value}}〉$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

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.

8  Further Comments

The total time taken by nag_quad_md_gauss (d01fbc) will be proportional to
 $T×nptvec[0]×nptvec[1]×⋯×nptvec[ndim-1],$
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 (d01fbce.c)

9.2  Program Data

Program Data (d01fbce.d)

9.3  Program Results

Program Results (d01fbce.r)

nag_quad_md_gauss (d01fbc) (PDF version)
d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual