SimplicialCubature
This package is a port of the R package SimplicalCubature, 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 3dimensional
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
integrateOnSimplex
, you have to define
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 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 z
: type P = x + y + 0*z
.
References

A. Genz and R. Cools. An adaptive numerical cubature algorithm for simplices. ACM Trans. Math. Software 29, 297308 (2003).

Jean B. Lasserre. Simple formula for the integration of polynomials on a simplex. BIT Numerical Mathematics 61, 523533 (2021).