﻿ d01pa Method
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

C#
```public static void d01pa(
int ndim,
double[,] vert,
D01..::..D01PA_FUNCTN functn,
ref int minord,
int maxord,
double[] finvls,
out double esterr,
out int ifail
)```
Visual Basic
```Public Shared Sub d01pa ( _
ndim As Integer, _
vert As Double(,), _
functn As D01..::..D01PA_FUNCTN, _
ByRef minord As Integer, _
maxord As Integer, _
finvls As Double(), _
<OutAttribute> ByRef esterr As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void d01pa(
int ndim,
array<double,2>^ vert,
D01..::..D01PA_FUNCTN^ functn,
int% minord,
int maxord,
array<double>^ finvls,
[OutAttribute] double% esterr,
[OutAttribute] int% ifail
)```
F#
```static member d01pa :
ndim : int *
vert : float[,] *
functn : D01..::..D01PA_FUNCTN *
minord : int byref *
maxord : int *
finvls : float[] *
esterr : float byref *
ifail : int byref -> unit
```

#### Parameters

ndim
Type: System..::..Int32
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 2$.
vert
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, sdvert]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{ndim}}+1$
On entry: ${\mathbf{vert}}\left[\mathit{i}-1,\mathit{j}-1\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 d01pa.
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 d01pa is made with ${\mathbf{minord}}>0$. In particular ${\mathbf{vert}}\left[n,2n+1\right]$ contains the volume of the simplex.
functn
Type: NagLibrary..::..D01..::..D01PA_FUNCTN
functn must return the value of the integrand $f$ at a given point.

A delegate of type D01PA_FUNCTN.

minord
Type: System..::..Int32%
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 d01pa.
Constraint: ${\mathbf{minord}}\ge 0$.
On exit: ${\mathbf{minord}}={\mathbf{maxord}}$.
maxord
Type: System..::..Int32
On entry: the highest order of approximation to the integral to be computed.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
finvls
Type: array<System..::..Double>[]()[][]
An array of size [maxord]
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 d01pa.
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$.
esterr
Type: System..::..Double%
On exit: an absolute error estimate for ${\mathbf{finvls}}\left[{\mathbf{maxord}}-1\right]$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

d01pa 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).

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDVERT) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ldvert}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldvert}}\ge {\mathbf{ndim}}+1$.
On entry, ${\mathbf{maxord}}=〈\mathit{\text{value}}〉$ and ${\mathbf{minord}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
On entry, ${\mathbf{minord}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{minord}}\ge 0$.
On entry, ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ndim}}\ge 2$.
On entry, ${\mathbf{sdvert}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ndim}}=〈\mathit{\text{value}}〉$.
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}}=-999$
Dynamic memory allocation failed.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

An absolute error estimate is output through the parameter esterr.

# Parallelism and Performance

None.

The running time for d01pa will usually be dominated by the time used to evaluate the integrand functn. The maximum time that could be used by 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 method with the integral
 $∫01∫01-x∫01-x-yexpx+y+zcosx+y+zdzdydx=14.$

Example program (C#): d01pae.cs

Example program results: d01pae.r