# NAG FL Interfaced01paf (md_​simplex)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine d01paf ( ndim, vert, f,
 Integer, Intent (In) :: ndim, ldvert, sdvert, maxord Integer, Intent (Inout) :: minord, ifail Real (Kind=nag_wp), External :: f Real (Kind=nag_wp), Intent (Inout) :: vert(ldvert,sdvert), finvls(maxord) Real (Kind=nag_wp), Intent (Out) :: esterr
#include <nag.h>
 void d01paf_ (const Integer *ndim, double vert[], const Integer *ldvert, const Integer *sdvert, double (NAG_CALL *f)(const Integer *ndim, const double x[]),Integer *minord, const Integer *maxord, double finvls[], double *esterr, Integer *ifail)
The routine may be called by the names d01paf or nagf_quad_md_simplex.

## 3Description

d01paf computes a sequence of approximations ${\mathbf{finvls}}\left(\mathit{j}\right)$, for $\mathit{j}={\mathbf{minord}}+1,\dots ,{\mathbf{maxord}}$, to an integral
 $∫Sf(x1,x2,…,xn)dx1dx2⋯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).
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

## 5Arguments

1: $\mathbf{ndim}$Integer Input
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 2$.
2: $\mathbf{vert}\left({\mathbf{ldvert}},{\mathbf{sdvert}}\right)$Real (Kind=nag_wp) array Input/Output
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 d01paf.
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 d01paf is made with ${\mathbf{minord}}>0$. In particular ${\mathbf{vert}}\left(n+1,2n+2\right)$ contains the volume of the simplex.
3: $\mathbf{ldvert}$Integer Input
On entry: the first dimension of the array vert as declared in the (sub)program from which d01paf is called.
Constraint: ${\mathbf{ldvert}}\ge {\mathbf{ndim}}+1$.
4: $\mathbf{sdvert}$Integer Input
On entry: the second dimension of the array vert as declared in the (sub)program from which d01paf is called.
Constraint: ${\mathbf{sdvert}}\ge 2×\left({\mathbf{ndim}}+1\right)$.
5: $\mathbf{f}$real (Kind=nag_wp) Function, supplied by the user. External Procedure
f must return the value of the integrand at a given point.
The specification of f is:
Fortran Interface
 Function f ( ndim, x)
 Real (Kind=nag_wp) :: f Integer, Intent (In) :: ndim Real (Kind=nag_wp), Intent (In) :: x(ndim)
 double f (const Integer *ndim, const double x[])
1: $\mathbf{ndim}$Integer Input
On entry: $n$, the number of dimensions of the integral.
2: $\mathbf{x}\left({\mathbf{ndim}}\right)$Real (Kind=nag_wp) array Input
On entry: the coordinates of the point at which the integrand $f$ must be evaluated.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d01paf is called. Arguments denoted as Input must not be changed by this procedure.
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01paf. If your code inadvertently does return any NaNs or infinities, d01paf is likely to produce unexpected results.
6: $\mathbf{minord}$Integer 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(1\right),{\mathbf{finvls}}\left(2\right),\dots ,{\mathbf{finvls}}\left({\mathbf{minord}}\right)$ have already been computed in a previous call of d01paf.
Constraint: ${\mathbf{minord}}\ge 0$.
On exit: ${\mathbf{minord}}={\mathbf{maxord}}$.
7: $\mathbf{maxord}$Integer Input
On entry: the highest order of approximation to the integral to be computed.
Constraint: ${\mathbf{maxord}}>{\mathbf{minord}}$.
8: $\mathbf{finvls}\left({\mathbf{maxord}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: 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 d01paf.
On exit: 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$.
9: $\mathbf{esterr}$Real (Kind=nag_wp) Output
On exit: an absolute error estimate for ${\mathbf{finvls}}\left({\mathbf{maxord}}\right)$.
10: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\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}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

An absolute error estimate is output through the argument esterr.

## 8Parallelism and Performance

d01paf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
d01paf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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

## 10Example

This example demonstrates the use of the subroutine with the integral
 $∫01 ∫01-x ∫01-x-y exp(x+y+z) cos(x+y+z) dz dy dx = 14 .$

### 10.1Program Text

Program Text (d01pafe.f90)

None.

### 10.3Program Results

Program Results (d01pafe.r)