Welcome to pysimplicialcubature’s documentation!¶
This package is a port of a part 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. In addition it provides a function for the exact computation of the integral of a polynomial over a simplex.
Indices and tables¶
Members functions¶
- pysimplicialcubature.simplicialcubature.integrateOnSimplex(f, S, dim=1, maxEvals=10000, absError=0.0, tol=1e-05, rule=3, info=False)¶
Integration on a simplex.
- Parameters:
f (function) – The function to be integrated.
S (array-like) – Simplex or simplices; a n-dimensional simplex is given as n+1 vectors of length n, the vertices.
dim (integer) – The dimension of the values of f.
maxEvals (integer) – Maximum number of calls to f.
absError (number) – Desired absolute error.
tol (number) – Desired relative error.
rule (integer) – Integer between 1 and 4 corresponding to the integration rule; a 2*rule+1 degree rule will be applied.
info (Boolean) – Whether to return more info.
- Returns:
The value of the integral is in the field “integral” of the returned value.
- Return type:
dictionary
Examples
>>> from pysimplicialcubature.simplicialcubature import integrateOnSimplex >>> from math import exp >>> # simplex vertices >>> v1 = [0.0, 0.0, 0.0] >>> v2 = [1.0, 1.0, 1.0] >>> v3 = [0.0, 1.0, 1.0] >>> v4 = [0.0, 0.0, 1.0] >>> # simplex >>> S = [v1, v2, v3, v4] >>> # function to integrate >>> f = lambda x : exp(x[0] + x[1] + x[2]) >>> # integral of f on S >>> I_f = integrateOnSimplex(f, S) >>> I_f["integral"]
- pysimplicialcubature.simplicialcubature.integratePolynomialOnSimplex(P, S)¶
Integration of a polynomial on a simplex.
- Parameters:
P (polynomial) – The polynomial to be integrated.
S (array-like) – Simplex; a n-dimensional simplex is given as n+1 vectors of length n, the vertices.
- Returns:
The value of the integral of the polynomial over the simplex.
- Return type:
number
Examples
>>> from pysimplicialcubature.simplicialcubature import integratePolynomialOnSimplex >>> from sympy import Poly >>> from sympy.abc import x, y, z >>> # simplex vertices >>> v1 = [0.0, 0.0, 0.0] >>> v2 = [1.0, 1.0, 1.0] >>> v3 = [0.0, 1.0, 1.0] >>> v4 = [0.0, 0.0, 1.0] >>> # simplex >>> S = [v1, v2, v3, v4] >>> # polynomial to integrate >>> P = Poly(x**4 + y + 2*x*y**2 - 3*z, x, y, z, domain = "RR") >>> # integral of P on S >>> integratePolynomialOnSimplex(P, S)
References¶
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).