SimplicialCubature.jl
Integration on simplices.
Install / Use
/learn @stla/SimplicialCubature.jlREADME
SimplicialCubature
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 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 procedure,
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)
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).
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
