SimplicialCubature.jl documentation
This package is a port of the R package SimplicialCubature, written by John P. Nolan, and which contains R translations of some Matlab and Fortran code written by Alan Genz.
___
A simplex is a triangle in dimension 2, a tetrahedron in dimension 3.  This package provides two main functions: integrateOnSimplex, to integrate  an arbitrary function on a simplex, and integratePolynomialOnSimplex, to  get the exact value of the integral of a multivariate polynomial on a  simplex.
A $n$-dimensional simplex must be given by $n+1$ vectors of length $n$, which represent the simplex vertices. For example, the $3$-dimensional unit simplex is encoded as follows:
S = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]Or you can get it by running CanonicalSimplex(3).
Suppose you want to integrate the function
\[f(x, y ,z) = x + yz\]
on the unit simplex. To use integrateOnSimplex, you have to define $f$  as a function of a 3-dimensional vector:
function f(x)
  return x[1] + x[2]*x[3]
end
using SimplicialCubature
I = integrateOnSimplex(f, S)Then the value of the integral is given in I.integral.
Since the function $f$ of this example is polynomial, you can use  integratePolynomialOnSimplex:
using SimplicialCubature
using TypedPolynomials
@polyvar x y z
P = x + y*z
integratePolynomialOnSimplex(P, S)Be careful if your polynomial does not involve one of the variables.  For example if $P(x, y, z) = x + y$, you have to encode it as a polynomial  depending on $z$: type P = x + y + 0*z.
In addition, on this example where the vertex coordinates of $S$ and the  coefficients of $P$ are integer numbers, there is a more clever way to  proceed: while integratePolynomialOnSimplex implements an exact proedure,  it is not free of (small) numerical errors, but the returned value in this  situation will be really exact if you use a polynomial with rational  coefficients:
@polyvar x y z
P = 1//1*x + y*z
integratePolynomialOnSimplex(P, S)Member functions
SimplicialCubature.CanonicalSimplex — MethodCanonicalSimplex(n)Canonical n-dimensional simplex.
Argument
n: positive integer
SimplicialCubature.integrateOnSimplex — MethodintegrateOnSimplex(f, S; dim, maxEvals, absError, tol, rule, info, fkwargs...)Integration of a function over one or more simplices.
Arguments
f: function to be integrated; must return a real scalar value or a real vectorS: simplex or vector of simplices; a simplex is given by n+1 vectors of dimension ndim: number of components offmaxEvals: maximum number of calls tofabsError: requested absolute errortol: requested relative errorrule: integration rule, an integer between 1 and 4; a 2*rule+1 degree integration rule is usedinfo: Boolean, whether to print more infofkwargs: keywords arguments off
SimplicialCubature.integratePolynomialOnSimplex — MethodintegratePolynomialOnSimplex(P, S)Exact integral of a polynomial over a simplex.
Argument
P: polynomialS: simplex, given by a vector of n+1 vectors of dimension n, the simplex vertices
References
- A. Genz and R. Cools.
 
An adaptive numerical cubature algorithm for simplices. ACM Trans. Math. Software 29, 297-308 (2003).
- Jean B. Lasserre.
 
Simple formula for the integration of polynomials on a simplex. BIT Numerical Mathematics 61, 523-533 (2021).