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 ${\mathbf{finvls}}\left(\mathit{j}\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\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).

## 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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ndim}$int64int32nag_int scalar
$n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 2$.
2:     $\mathrm{vert}\left(\mathit{ldvert},{\mathbf{sdvert}}\right)$ – double array
ldvert, the first dimension of the array, must satisfy the constraint $\mathit{ldvert}\ge {\mathbf{ndim}}+1$.
${\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 (d01pa).
3:     $\mathrm{functn}$ – function handle or string containing name of m-file
functn must return the value of the integrand $f$ at a given point.
[result] = functn(ndim, x)

Input Parameters

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

Output Parameters

1:     $\mathrm{result}$ – double scalar
The value of the integrand $f$ at the given point.
4:     $\mathrm{minord}$int64int32nag_int scalar
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(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: ${\mathbf{minord}}\ge 0$.
5:     $\mathrm{finvls}\left({\mathbf{maxord}}\right)$ – double array
If ${\mathbf{minord}}>0$, ${\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:     $\mathrm{sdvert}$int64int32nag_int scalar
Default: the second dimension of the array vert.
The second dimension of the array vert.
Constraint: ${\mathbf{sdvert}}\ge 2×\left({\mathbf{ndim}}+1\right)$.
2:     $\mathrm{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}}$.

### Output Parameters

1:     $\mathrm{vert}\left(\mathit{ldvert},{\mathbf{sdvert}}\right)$ – double array
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 ${\mathbf{minord}}>0$. In particular ${\mathbf{vert}}\left(n+1,2n+2\right)$ contains the volume of the simplex.
2:     $\mathrm{minord}$int64int32nag_int scalar
${\mathbf{minord}}={\mathbf{maxord}}$.
3:     $\mathrm{finvls}\left({\mathbf{maxord}}\right)$ – double array
Contains these values unchanged, and the newly computed values ${\mathbf{finvls}}\left({\mathbf{minord}}+1\right),{\mathbf{finvls}}\left({\mathbf{minord}}+2\right),\dots ,{\mathbf{finvls}}\left({\mathbf{maxord}}\right)$. ${\mathbf{finvls}}\left(j\right)$ is an approximation to the integral of polynomial degree $2j-1$.
4:     $\mathrm{esterr}$ – double scalar
An absolute error estimate for ${\mathbf{finvls}}\left({\mathbf{maxord}}\right)$.
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
Constraint: $\mathit{ldvert}\ge {\mathbf{ndim}}+1$.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
Constraint: ${\mathbf{minord}}\ge 0$.
Constraint: ${\mathbf{ndim}}\ge 2$.
Constraint: ${\mathbf{sdvert}}\ge 2×\left({\mathbf{ndim}}+1\right)$.
${\mathbf{ifail}}=2$
The volume of the simplex integration region is too large or too small to be represented on the machine.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

An absolute error estimate is output through the argument 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!$
where $T$ is the time needed for one call of functn.

## 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 .$
```function d01pa_example

fprintf('d01pa example results\n\n');

ndim = int64(3);
vertex = zeros(ndim+1,2*(ndim+1));
vertex(2:ndim+1,1:ndim) = eye(3);
minord = int64(0);
finvls = zeros(5,1);

fprintf('Maxord   Estimated      Estimated         Integrand\n');
fprintf('           value         accuracy        evaluations\n');
nevals = 1;
for maxord = int64(1:5)
[vertex, minord, finvls, esterr, ifail] = ...
d01pa(...
ndim, vertex, @functn, minord, finvls,'maxord',maxord);

fprintf('%5d%13.5f%16.3e%15d\n',maxord, finvls(maxord),esterr,nevals);
nevals = (nevals*(maxord+ndim+1))/maxord;
end

function result = functn(ndim, x)
u = sum(x);
result = exp(u)*cos(u);
```
```d01pa example results

Maxord   Estimated      Estimated         Integrand
value         accuracy        evaluations
1      0.25816       2.582e-01              1
2      0.25011       8.058e-03              5
3      0.25000       1.067e-04             15
4      0.25000       4.098e-07             35
5      0.25000       1.731e-09             70
```