d01 Chapter Contents
d01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_quad_md_simplex (d01pac)

## 1  Purpose

nag_quad_md_simplex (d01pac) returns a sequence of approximations to the integral of a function over a multidimensional simplex, together with an error estimate for the last approximation.

## 2  Specification

 #include #include
void  nag_quad_md_simplex (Integer ndim, double vert[],
 double (*functn)(Integer ndim, const double x[], Nag_Comm *comm),
Integer *minord, Integer maxord, double finvls[], double *esterr, Nag_Comm *comm, NagError *fail)

## 3  Description

nag_quad_md_simplex (d01pac) computes a sequence of approximations ${\mathbf{finvls}}\left[\mathit{j}-1\right]$, for $\mathit{j}={\mathbf{minord}}+1,\dots ,{\mathbf{maxord}}$, to an integral
 $∫Sfx1,x2,…,xndx1dx2⋯dxn$
where $S$ is an $n$-dimensional simplex defined in terms of its $n+1$ vertices. ${\mathbf{finvls}}\left[j-1\right]$ is an approximation which will be exact (except for rounding errors) whenever the integrand is a polynomial of total degree $2j-1$ or less.
The type of method used has been described in Grundmann and Moller (1978), and is implemented in an extrapolated form using the theory from de Doncker (1979).

## 4  References

de Doncker E (1979) New Euler–Maclaurin Expansions and their application to quadrature over the $s$-dimensional simplex Math. Comput. 33 1003–1018
Grundmann A and Moller H M (1978) Invariant integration formulas for the $n$-simplex by combinatorial methods SIAM J. Numer. Anal. 15 282–290

## 5  Arguments

1:     ndimIntegerInput
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 2$.
2:     vert[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array vert must be at least $\left(2×\left({\mathbf{ndim}}+1\right)\right)×\left({\mathbf{ndim}}+1\right)$.
Where ${\mathbf{VERT}}\left(i,j\right)$ appears in this document, it refers to the array element ${\mathbf{vert}}\left[\left(j-1\right)×\left({\mathbf{ndim}}+1\right)+i-1\right]$.
On entry: ${\mathbf{VERT}}\left(\mathit{i},\mathit{j}\right)$ must be set to the $\mathit{j}$th component of the $\mathit{i}$th vertex for the simplex integration region, for $\mathit{i}=1,2,\dots ,n+1$ and $\mathit{j}=1,2,\dots ,n$. If ${\mathbf{minord}}>0$, vert must be unchanged since the previous call of nag_quad_md_simplex (d01pac).
On exit: these values are unchanged. The rest of the array vert is used for workspace and contains information to be used if another call of nag_quad_md_simplex (d01pac) is made with ${\mathbf{minord}}>0$. In particular ${\mathbf{VERT}}\left(n+1,2n+2\right)$ contains the volume of the simplex.
3:     functnfunction, supplied by the userExternal Function
functn must return the value of the integrand $f$ at a given point.
The specification of functn is:
 double functn (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 functn.
userdouble *
iuserInteger *
pPointer
The type Pointer will be void *. Before calling nag_quad_md_simplex (d01pac) you may allocate memory and initialize these pointers with various quantities for use by functn when called from nag_quad_md_simplex (d01pac) (see Section 3.2.1 in the Essential Introduction).
4:     minordInteger *Input/Output
On entry: must specify the highest order of the approximations currently available in the array finvls. ${\mathbf{minord}}=0$ indicates an initial call; ${\mathbf{minord}}>0$ indicates that ${\mathbf{finvls}}\left[0\right],{\mathbf{finvls}}\left[1\right],\dots ,{\mathbf{finvls}}\left[{\mathbf{minord}}-1\right]$ have already been computed in a previous call of nag_quad_md_simplex (d01pac).
Constraint: ${\mathbf{minord}}\ge 0$.
On exit: ${\mathbf{minord}}={\mathbf{maxord}}$.
5:     maxordIntegerInput
On entry: the highest order of approximation to the integral to be computed.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
6:     finvls[maxord]doubleInput/Output
On entry: if ${\mathbf{minord}}>0$, ${\mathbf{finvls}}\left[0\right],{\mathbf{finvls}}\left[1\right],\dots ,{\mathbf{finvls}}\left[{\mathbf{minord}}-1\right]$ must contain approximations to the integral previously computed by nag_quad_md_simplex (d01pac).
On exit: contains these values unchanged, and the newly computed values ${\mathbf{finvls}}\left[{\mathbf{minord}}\right],{\mathbf{finvls}}\left[{\mathbf{minord}}+1\right],\dots ,{\mathbf{finvls}}\left[{\mathbf{maxord}}-1\right]$. ${\mathbf{finvls}}\left[j-1\right]$ is an approximation to the integral of polynomial degree $2j-1$.
7:     esterrdouble *Output
On exit: an absolute error estimate for ${\mathbf{finvls}}\left[{\mathbf{maxord}}-1\right]$.
8:     commNag_Comm *Communication Structure
The NAG communication argument (see Section 3.2.1.1 in the Essential Introduction).
9:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ACCURACY
The volume of the simplex integration region is too large or too small to be represented on the machine.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{minord}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{minord}}\ge 0$.
On entry, ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ndim}}\ge 2$.
NE_INT_2
On entry, ${\mathbf{maxord}}=〈\mathit{\text{value}}〉$ and ${\mathbf{minord}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
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

An absolute error estimate is output through the argument esterr.

The running time for nag_quad_md_simplex (d01pac) will usually be dominated by the time used to evaluate the integrand functn. The maximum time that could be used by nag_quad_md_simplex (d01pac) will be approximately given by
 $T×maxord+ndim! maxord-1!ndim+1!$
where $T$ is the time needed for one call of functn.

## 9  Example

This example demonstrates the use of the function with the integral
 $∫01 ∫01-x ∫01-x-y expx+y+z cosx+y+z dz dy dx = 14 .$

### 9.1  Program Text

Program Text (d01pace.c)

### 9.2  Program Data

Program Data (d01pace.d)

### 9.3  Program Results

Program Results (d01pace.r)