Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

## Purpose

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

## Syntax

[vert, minord, finvls, esterr, ifail] = d01pa(ndim, vert, functn, minord, finvls, 'sdvert', sdvert, 'maxord', maxord)
[vert, minord, finvls, esterr, ifail] = nag_quad_md_simplex(ndim, vert, functn, minord, finvls, 'sdvert', sdvert, 'maxord', maxord)

## Description

nag_quad_md_simplex (d01pa) computes a sequence of approximations finvls(j)${\mathbf{finvls}}\left(\mathit{j}\right)$, for j = minord + 1,,maxord$\mathit{j}={\mathbf{minord}}+1,\dots ,{\mathbf{maxord}}$, to an integral
 ∫Sf(x1,x2, … ,xn)dx1dx2 ⋯ dxn$∫Sf(x1,x2,…,xn)dx1dx2⋯dxn$
where S$S$ is an n$n$-dimensional simplex defined in terms of its n + 1$n+1$ vertices. finvls(j)${\mathbf{finvls}}\left(j\right)$ is an approximation which will be exact (except for rounding errors) whenever the integrand is a polynomial of total degree 2j1$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).

## References

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

## Parameters

### Compulsory Input Parameters

1:     ndim – int64int32nag_int scalar
n$n$, the number of dimensions of the integral.
Constraint: ndim2${\mathbf{ndim}}\ge 2$.
2:     vert(ldvert,sdvert) – double array
ldvert, the first dimension of the array, must satisfy the constraint ldvertndim + 1$\mathit{ldvert}\ge {\mathbf{ndim}}+1$.
vert(i,j)${\mathbf{vert}}\left(\mathit{i},\mathit{j}\right)$ must be set to the j$\mathit{j}$th component of the i$\mathit{i}$th vertex for the simplex integration region, for i = 1,2,,n + 1$\mathit{i}=1,2,\dots ,n+1$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,n$. If minord > 0${\mathbf{minord}}>0$, vert must be unchanged since the previous call of nag_quad_md_simplex (d01pa).
3:     functn – function handle or string containing name of m-file
functn must return the value of the integrand f$f$ at a given point.
[result] = functn(ndim, x)

Input Parameters

1:     ndim – int64int32nag_int scalar
n$n$, the number of dimensions of the integral.
2:     x(ndim) – double array
The coordinates of the point at which the integrand f$f$ must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.
4:     minord – int64int32nag_int scalar
Must specify the highest order of the approximations currently available in the array finvls. minord = 0${\mathbf{minord}}=0$ indicates an initial call; minord > 0${\mathbf{minord}}>0$ indicates that finvls(1),finvls(2),,${\mathbf{finvls}}\left(1\right),{\mathbf{finvls}}\left(2\right),\dots ,{\mathbf{finvls}}\left({\mathbf{minord}}\right)$ have already been computed in a previous call of nag_quad_md_simplex (d01pa).
Constraint: minord0${\mathbf{minord}}\ge 0$.
5:     finvls(maxord) – double array
maxord, the dimension of the array, must satisfy the constraint ${\mathbf{maxord}}>{\mathbf{minord}}$.
If minord > 0${\mathbf{minord}}>0$, finvls(1),finvls(2),,${\mathbf{finvls}}\left(1\right),{\mathbf{finvls}}\left(2\right),\dots ,{\mathbf{finvls}}\left({\mathbf{minord}}\right)$ must contain approximations to the integral previously computed by nag_quad_md_simplex (d01pa).

### Optional Input Parameters

1:     sdvert – int64int32nag_int scalar
Default: The second dimension of the array vert.
The second dimension of the array vert as declared in the (sub)program from which nag_quad_md_simplex (d01pa) is called.
Constraint: sdvert2 × (ndim + 1)${\mathbf{sdvert}}\ge 2×\left({\mathbf{ndim}}+1\right)$.
2:     maxord – int64int32nag_int scalar
Default: The dimension of the array finvls.
The highest order of approximation to the integral to be computed.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.

ldvert

### Output Parameters

1:     vert(ldvert,sdvert) – double array
ldvertndim + 1$\mathit{ldvert}\ge {\mathbf{ndim}}+1$.
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 (d01pa) is made with minord > 0${\mathbf{minord}}>0$. In particular vert(n + 1,2n + 2)${\mathbf{vert}}\left(n+1,2n+2\right)$ contains the volume of the simplex.
2:     minord – int64int32nag_int scalar
${\mathbf{minord}}={\mathbf{maxord}}$.
3:     finvls(maxord) – double array
Contains these values unchanged, and the newly computed values finvls(minord + 1),finvls(minord + 2),,${\mathbf{finvls}}\left({\mathbf{minord}}+1\right),{\mathbf{finvls}}\left({\mathbf{minord}}+2\right),\dots ,{\mathbf{finvls}}\left({\mathbf{maxord}}\right)$. finvls(j)${\mathbf{finvls}}\left(j\right)$ is an approximation to the integral of polynomial degree 2j1$2j-1$.
4:     esterr – double scalar
An absolute error estimate for ${\mathbf{finvls}}\left({\mathbf{maxord}}\right)$.
5:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, ndim < 2${\mathbf{ndim}}<2$, or ldvert < ndim + 1$\mathit{ldvert}<{\mathbf{ndim}}+1$, or sdvert < 2 × (ndim + 1)${\mathbf{sdvert}}<2×\left({\mathbf{ndim}}+1\right)$, or minord < 0${\mathbf{minord}}<0$, or ${\mathbf{maxord}}\le {\mathbf{minord}}$.
ifail = 2${\mathbf{ifail}}=2$
The volume of the simplex integration region (computed as a determinant by a function from Chapter F03) is too large or too small to be representable in the machine.

## Accuracy

An absolute error estimate is output through the parameter esterr.

The running time for nag_quad_md_simplex (d01pa) 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 (d01pa) will be approximately given by
 T × ((maxord + ndim) ! )/((maxord − 1) ! (ndim + 1) ! ) $T×(maxord+ndim)! (maxord-1)!(ndim+1)!$
where T$T$ is the time needed for one call of functn.

## Example

```function nag_quad_md_simplex_example
ndim = int64(3);
vertex = [0, 0, 0, 0, 0, 0, 0, 0;
1, 0, 0, 0, 0, 0, 0, 0;
0, 1, 0, 0, 0, 0, 0, 0;
0, 0, 1, 0, 0, 0, 0, 0];
minord = int64(0);
finvls = [0];
[vertexOut, minordOut, finvlsOut, esterr, ifail] = ...

function result = functn(ndim, x)
result = exp(x(1)+x(2)+x(3))*cos(x(1)+x(2)+x(3));
```
```

vertexOut =

0         0         0         0         0   -0.5000         0    0.2500
1.0000         0         0    0.5000         0   -0.5000         0    0.2500
0    1.0000         0         0    0.5000   -0.5000         0    0.2500
0         0    1.0000         0         0         0    3.0000    1.0000

minordOut =

1

finvlsOut =

0.2582

esterr =

0.2582

ifail =

0

```
```function d01pa_example
ndim = int64(3);
vertex = [0, 0, 0, 0, 0, 0, 0, 0;
1, 0, 0, 0, 0, 0, 0, 0;
0, 1, 0, 0, 0, 0, 0, 0;
0, 0, 1, 0, 0, 0, 0, 0];
minord = int64(0);
finvls = [0];
[vertexOut, minordOut, finvlsOut, esterr, ifail] = ...
d01pa(ndim, vertex, @functn, minord, finvls)

function result = functn(ndim, x)
result = exp(x(1)+x(2)+x(3))*cos(x(1)+x(2)+x(3));
```
```

vertexOut =

0         0         0         0         0   -0.5000         0    0.2500
1.0000         0         0    0.5000         0   -0.5000         0    0.2500
0    1.0000         0         0    0.5000   -0.5000         0    0.2500
0         0    1.0000         0         0         0    3.0000    1.0000

minordOut =

1

finvlsOut =

0.2582

esterr =

0.2582

ifail =

0

```