Integration on simplices.
Project description
pysimplicialcubature
This package is a port of a part 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. In addition it provides a function for the exact computation of the integral of a polynomial over a simplex.
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.
Suppose for example you want to evaluate the following integral:
$$\int_0^1\int_0^x\int_0^y \exp(x + y + z) \text{d}z \text{d}y \text{d}x.$$
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"]
Now let's turn to a polynomial example. You have to define the polynomial with
sympy.Poly
.
from pysimplicialcubature.simplicialcubature import integratePolynomialOnSimplex
from sympy import Poly
from sympy.abc import x, y, z
# simplex vertices
v1 = [1.0, 1.0, 1.0]
v2 = [2.0, 2.0, 3.0]
v3 = [3.0, 4.0, 5.0]
v4 = [3.0, 2.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
-
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pysimplicialcubature-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 263a4929a3be047548fdf3401d1b4c966a773650464008e90ccadd3d2a092968 |
|
MD5 | 1b4ecdd0a4dd6d05cf00b1033f1a611c |
|
BLAKE2b-256 | 7da79273577c7757b0e593c84aae3c31d7af875e6db38dce83fd79a7d6cebb66 |
Hashes for pysimplicialcubature-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1f6eacb816bbcf8db89c268d4e0e8675fae2a6243cca4e75ff4684be4b361ca |
|
MD5 | b18540029e1f012bdc0389c4b3807454 |
|
BLAKE2b-256 | 6a8394655233d96eca3417d3a91bf9de2827456fe212510b21873e3972e2c2a8 |