积分#

这个 integrals SymPy中的模块实现了计算表达式的定积分和不定积分的方法。

本模块的主要方法是 integrate()

  • integrate(f, x) returns the indefinite integral \(\int f\,dx\)

  • integrate(f, (x, a, b)) returns the definite integral \(\int_{a}^{b} f\,dx\)

实例#

SymPy可以集成大量的功能。它可以积分多项式函数:

>>> from sympy import *
>>> init_printing(use_unicode=False, wrap_line=False)
>>> x = Symbol('x')
>>> integrate(x**2 + x + 1, x)
 3    2
x    x
-- + -- + x
3    2

有理函数:

>>> integrate(x/(x**2+2*x+1), x)
               1
log(x + 1) + -----
             x + 1

指数多项式函数。多项式和函数的乘法组合 expcossin 可以手工集成使用重复集成零件,这是一个非常繁琐的过程。幸运的是,SymPy将处理这些积分。

>>> integrate(x**2 * exp(x) * cos(x), x)
 2  x           2  x                         x           x
x *e *sin(x)   x *e *cos(x)      x          e *sin(x)   e *cos(x)
------------ + ------------ - x*e *sin(x) + --------- - ---------
     2              2                           2           2

甚至一些非基本积分(特别是一些涉及误差函数的积分)也可以计算:

>>> integrate(exp(-x**2)*erf(x), x)
  ____    2
\/ pi *erf (x)
--------------
      4

积分变换#

SymPy对定积分和积分变换有特殊的支持。

sympy.integrals.transforms.mellin_transform(f, x, s, **hints)[源代码]#

计算梅林变换 \(F(s)\) 属于 \(f(x)\)

\[F(s)=\int_0^\infty x^{s-1}F(x)\mathrm{d}x。\]
对于所有“合理”的函数,这是绝对收敛于一条带中的

\(a < \operatorname{{Re}}(s) < b\) .

解释

Mellin变换通过变量的变化与Fourier变换以及(双边)Laplace变换相关联。

此函数返回 (F, (a, b), cond) 在哪里? F 梅林变换 f(a, b) 是基本条带(如上所述),以及 cond 是辅助收敛条件。

如果积分不能以闭合形式计算,此函数将返回未赋值的 MellinTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() .如果 noconds=False 然后,只有 \(F\) 将被退回(即 cond ,也不是长条 (a, b)

实例

>>> from sympy import mellin_transform, exp
>>> from sympy.abc import x, s
>>> mellin_transform(exp(-x), x, s)
(gamma(s), (0, oo), True)
class sympy.integrals.transforms.MellinTransform(*args)[源代码]#

类表示未赋值的Mellin变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算Mellin变换,请参见 mellin_transform() 文档字符串。

sympy.integrals.transforms.inverse_mellin_transform(F, s, x, strip, **hints)[源代码]#

求逆Mellin变换 \(F(s)\) 在基本条上 strip=(a, b) .

解释

这可以定义为

\[f(x)=\frac{1}{2\pii}\int{c-i\infty}^{c+i\infty}x^{-s}f(s)\mathrm{d}s,\]

对于任何 \(c\) 在基本面上。在一定的正则条件下 \(F\) 和/或 \(f\) ,恢复 \(f\) 从它的梅林变换 \(F\) (反之亦然),为正实数 \(x\) .

什么之中的一个 \(a\)\(b\) 可作为 None ;合适的 \(c\) 将被推断。

如果积分不能以闭合形式计算,此函数将返回未赋值的 InverseMellinTransform 对象。

Note that this function will assume x to be positive and real, regardless of the SymPy assumptions!

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() .

实例

>>> from sympy import inverse_mellin_transform, oo, gamma
>>> from sympy.abc import x, s
>>> inverse_mellin_transform(gamma(s), s, x, (0, oo))
exp(-x)

最重要的是:

>>> f = 1/(s**2 - 1)
>>> inverse_mellin_transform(f, s, x, (-oo, -1))
x*(1 - 1/x**2)*Heaviside(x - 1)/2
>>> inverse_mellin_transform(f, s, x, (-1, 1))
-x*Heaviside(1 - x)/2 - Heaviside(x - 1)/(2*x)
>>> inverse_mellin_transform(f, s, x, (1, oo))
(1/2 - x**2/2)*Heaviside(1 - x)/x
class sympy.integrals.transforms.InverseMellinTransform(*args)[源代码]#

类表示未赋值的反向Mellin变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算逆Mellin变换,请参见 inverse_mellin_transform() 文档字符串。

sympy.integrals.transforms.laplace_transform(f, t, s, legacy_matrix=True, **hints)[源代码]#

计算拉普拉斯变换 \(F(s)\) 属于 \(f(t)\)

\[F(s) = \int_{0^{-}}^\infty e^{-st} f(t) \mathrm{d}t.\]

解释

For all sensible functions, this converges absolutely in a half-plane

\[a < \operatorname{Re}(s)\]

This function returns (F, a, cond) where F is the Laplace transform of f, \(a\) is the half-plane of convergence, and \(cond\) are auxiliary convergence conditions.

The implementation is rule-based, and if you are interested in which rules are applied, and whether integration is attempted, you can switch debug information on by setting sympy.SYMPY_DEBUG=True. The numbers of the rules in the debug information (and the code) refer to Bateman's Tables of Integral Transforms [1].

The lower bound is \(0-\), meaning that this bound should be approached from the lower side. This is only necessary if distributions are involved. At present, it is only done if \(f(t)\) contains DiracDelta, in which case the Laplace transform is computed implicitly as

\[F(s) = \lim_{\tau\to 0^{-}} \int_{\tau}^\infty e^{-st} f(t) \mathrm{d}t\]

by applying rules.

If the Laplace transform cannot be fully computed in closed form, this function returns expressions containing unevaluated LaplaceTransform objects.

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() .如果 noconds=True ,只有 \(F\) 将被退回(即 cond 也不是飞机 a

自 1.9 版本弃用: Legacy behavior for matrices where laplace_transform with noconds=False (the default) returns a Matrix whose elements are tuples. The behavior of laplace_transform for matrices will change in a future release of SymPy to return a tuple of the transformed Matrix and the convergence conditions for the matrix as a whole. Use legacy_matrix=False to enable the new behavior.

实例

>>> from sympy import DiracDelta, exp, laplace_transform
>>> from sympy.abc import t, s, a
>>> laplace_transform(t**4, t, s)
(24/s**5, 0, True)
>>> laplace_transform(t**a, t, s)
(gamma(a + 1)/(s*s**a), 0, re(a) > -1)
>>> laplace_transform(DiracDelta(t)-a*exp(-a*t), t, s, simplify=True)
(s/(a + s), -re(a), True)

There are also helper functions that make it easy to solve differential equations by Laplace transform. For example, to solve

\[m x''(t) + d x'(t) + k x(t) = 0\]

with initial value \(0\) and initial derivative \(v\):

>>> from sympy import Function, laplace_correspondence, diff, solve
>>> from sympy import laplace_initial_conds, inverse_laplace_transform
>>> from sympy.abc import d, k, m, v
>>> x = Function('x')
>>> X = Function('X')
>>> f = m*diff(x(t), t, 2) + d*diff(x(t), t) + k*x(t)
>>> F = laplace_transform(f, t, s, noconds=True)
>>> F = laplace_correspondence(F, {x: X})
>>> F = laplace_initial_conds(F, t, {x: [0, v]})
>>> F
d*s*X(s) + k*X(s) + m*(s**2*X(s) - v)
>>> Xs = solve(F, X(s))[0]
>>> Xs
m*v/(d*s + k + m*s**2)
>>> inverse_laplace_transform(Xs, s, t)
2*v*exp(-d*t/(2*m))*sin(t*sqrt((-d**2 + 4*k*m)/m**2)/2)*Heaviside(t)/sqrt((-d**2 + 4*k*m)/m**2)

工具书类

[R567]

Erdelyi, A. (ed.), Tables of Integral Transforms, Volume 1, Bateman Manuscript Prooject, McGraw-Hill (1954), available: https://resolver.caltech.edu/CaltechAUTHORS:20140123-101456353

sympy.integrals.transforms.laplace_correspondence(f, fdict, /)[源代码]#

This helper function takes a function \(f\) that is the result of a laplace_transform or an inverse_laplace_transform. It replaces all unevaluated LaplaceTransform(y(t), t, s) by \(Y(s)\) for any \(s\) and all InverseLaplaceTransform(Y(s), s, t) by \(y(t)\) for any \(t\) if fdict contains a correspondence {y: Y}.

参数:

f : sympy expression

Expression containing unevaluated LaplaceTransform or LaplaceTransform objects.

fdict : dictionary

Dictionary containing one or more function correspondences, e.g., {x: X, y: Y} meaning that X and Y are the Laplace transforms of x and y, respectively.

实例

>>> from sympy import laplace_transform, diff, Function
>>> from sympy import laplace_correspondence, inverse_laplace_transform
>>> from sympy.abc import t, s
>>> y = Function("y")
>>> Y = Function("Y")
>>> z = Function("z")
>>> Z = Function("Z")
>>> f = laplace_transform(diff(y(t), t, 1) + z(t), t, s, noconds=True)
>>> laplace_correspondence(f, {y: Y, z: Z})
s*Y(s) + Z(s) - y(0)
>>> f = inverse_laplace_transform(Y(s), s, t)
>>> laplace_correspondence(f, {y: Y})
y(t)
sympy.integrals.transforms.laplace_initial_conds(f, t, fdict, /)[源代码]#

This helper function takes a function \(f\) that is the result of a laplace_transform. It takes an fdict of the form {y: [1, 4, 2]}, where the values in the list are the initial value, the initial slope, the initial second derivative, etc., of the function \(y(t)\), and replaces all unevaluated initial conditions.

参数:

f : sympy expression

Expression containing initial conditions of unevaluated functions.

t : sympy expression

Variable for which the initial conditions are to be applied.

fdict : dictionary

Dictionary containing a list of initial conditions for every function, e.g., {y: [0, 1, 2], x: [3, 4, 5]}. The order of derivatives is ascending, so \(0\), \(1\), \(2\) are \(y(0)\), \(y'(0)\), and \(y''(0)\), respectively.

实例

>>> from sympy import laplace_transform, diff, Function
>>> from sympy import laplace_correspondence, laplace_initial_conds
>>> from sympy.abc import t, s
>>> y = Function("y")
>>> Y = Function("Y")
>>> f = laplace_transform(diff(y(t), t, 3), t, s, noconds=True)
>>> g = laplace_correspondence(f, {y: Y})
>>> laplace_initial_conds(g, t, {y: [2, 4, 8, 16, 32]})
s**3*Y(s) - 2*s**2 - 4*s - 8
class sympy.integrals.transforms.LaplaceTransform(*args)[源代码]#

类表示未赋值的拉普拉斯变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算拉普拉斯变换的信息,请参见 laplace_transform() 文档字符串。

If this is called with .doit(), it returns the Laplace transform as an expression. If it is called with .doit(noconds=False), it returns a tuple containing the same expression, a convergence plane, and conditions.

doit(**hints)[源代码]#

尝试以闭合形式计算转换。

解释

Standard hints are the following: - noconds: if True, do not return convergence conditions. The default setting is \(True\). - simplify: if True, it simplifies the final result. The default setting is \(False\).

sympy.integrals.transforms.inverse_laplace_transform(F, s, t, plane=None, **hints)[源代码]#

计算拉普拉斯逆变换 \(F(s)\) ,定义为

\[f(t) = \frac{1}{2\pi i} \int_{c-i\infty}^{c+i\infty} e^{st} F(s) \mathrm{d}s,\]

对于 \(c\) 这么大以至于 \(F(s)\) 在半平面上没有奇点 \(\operatorname{{Re}}(s) > c-\epsilon\) .

解释

平面可以通过参数指定 plane ,但如果作为“无”传递,则将推断。

在一定的规律性条件下,它会恢复 \(f(t)\) 从它的拉普拉斯变换 \(F(s)\) ,表示非阴性 \(t\) ,反之亦然。

如果积分不能以闭合形式计算,此函数将返回未赋值的 InverseLaplaceTransform 对象。

Note that this function will always assume \(t\) to be real, regardless of the SymPy assumption on \(t\).

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() .

实例

>>> from sympy import inverse_laplace_transform, exp, Symbol
>>> from sympy.abc import s, t
>>> a = Symbol('a', positive=True)
>>> inverse_laplace_transform(exp(-a*s)/s, s, t)
Heaviside(-a + t)
class sympy.integrals.transforms.InverseLaplaceTransform(*args)[源代码]#

类表示未赋值的反拉普拉斯变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算反拉普拉斯变换,请参见 inverse_laplace_transform() 文档字符串。

doit(**hints)[源代码]#

尝试以闭合形式计算转换。

解释

Standard hints are the following: - noconds: if True, do not return convergence conditions. The default setting is \(True\). - simplify: if True, it simplifies the final result. The default setting is \(False\).

sympy.integrals.transforms.fourier_transform(f, x, k, **hints)[源代码]#

Compute the unitary, ordinary-frequency Fourier transform of f, defined as

\[F(k)=\int{-\infty}^\infty F(x)e^{-2\pi i x k}\mathrm{d}x。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 FourierTransform 对象。

有关其他傅里叶变换约定,请参见函数 sympy.integrals.transforms._fourier_transform() .

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import fourier_transform, exp
>>> from sympy.abc import x, k
>>> fourier_transform(exp(-x**2), x, k)
sqrt(pi)*exp(-pi**2*k**2)
>>> fourier_transform(exp(-x**2), x, k, noconds=False)
(sqrt(pi)*exp(-pi**2*k**2), True)
sympy.integrals.transforms._fourier_transform(f, x, k, a, b, name, simplify=True)[源代码]#

计算一般的Fourier型变换

\[F(k)=a\int{-\infty}^{\infty}e^{bixk}F(x)\,dx。\]

为合适的选择 ab ,这就简化为标准傅里叶变换和逆傅里叶变换。

class sympy.integrals.transforms.FourierTransform(*args)[源代码]#

类表示未赋值的傅立叶变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算傅立叶变换,请参见 fourier_transform() 文档字符串。

sympy.integrals.transforms.inverse_fourier_transform(F, k, x, **hints)[源代码]#

计算 \(F\) ,定义为

\[f(x)=\int{-\infty}\infty f(k)e^{2\pi i x k}\mathrm{d}k。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 InverseFourierTransform 对象。

有关其他傅里叶变换约定,请参见函数 sympy.integrals.transforms._fourier_transform() .

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import inverse_fourier_transform, exp, sqrt, pi
>>> from sympy.abc import x, k
>>> inverse_fourier_transform(sqrt(pi)*exp(-(pi*k)**2), k, x)
exp(-x**2)
>>> inverse_fourier_transform(sqrt(pi)*exp(-(pi*k)**2), k, x, noconds=False)
(exp(-x**2), True)
class sympy.integrals.transforms.InverseFourierTransform(*args)[源代码]#

表示未赋值的傅立叶逆变换的类。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算傅里叶逆变换,请参见 inverse_fourier_transform() 文档字符串。

sympy.integrals.transforms.sine_transform(f, x, k, **hints)[源代码]#

计算 \(f\) ,定义为

\[F(k)=\sqrt{\frac{2}{\pi}\int{0}^\infty F(x)\sin(2\pi x k)\mathrm{d}x。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 SineTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import sine_transform, exp
>>> from sympy.abc import x, k, a
>>> sine_transform(x*exp(-a*x**2), x, k)
sqrt(2)*k*exp(-k**2/(4*a))/(4*a**(3/2))
>>> sine_transform(x**(-a), x, k)
2**(1/2 - a)*k**(a - 1)*gamma(1 - a/2)/gamma(a/2 + 1/2)
class sympy.integrals.transforms.SineTransform(*args)[源代码]#

类表示未赋值的正弦变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算正弦变换,请参见 sine_transform() 文档字符串。

sympy.integrals.transforms.inverse_sine_transform(F, k, x, **hints)[源代码]#

计算 \(F\) ,定义为

\[f(x)=\sqrt{\frac{2}{\pi}\int{0}^\infty f(k)\sin(2\pi x k)\mathrm{d}k。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 InverseSineTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import inverse_sine_transform, exp, sqrt, gamma
>>> from sympy.abc import x, k, a
>>> inverse_sine_transform(2**((1-2*a)/2)*k**(a - 1)*
...     gamma(-a/2 + 1)/gamma((a+1)/2), k, x)
x**(-a)
>>> inverse_sine_transform(sqrt(2)*k*exp(-k**2/(4*a))/(4*sqrt(a)**3), k, x)
x*exp(-a*x**2)
class sympy.integrals.transforms.InverseSineTransform(*args)[源代码]#

表示未赋值的正弦逆变换的类。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算正弦逆变换,请参见 inverse_sine_transform() 文档字符串。

sympy.integrals.transforms.cosine_transform(f, x, k, **hints)[源代码]#

计算 \(f\) ,定义为

\[F(k)=\sqrt{\frac{2}{\pi}\int{0}}\infty F(x)\cos(2\pi x k)\mathrm{d}x。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 CosineTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import cosine_transform, exp, sqrt, cos
>>> from sympy.abc import x, k, a
>>> cosine_transform(exp(-a*x), x, k)
sqrt(2)*a/(sqrt(pi)*(a**2 + k**2))
>>> cosine_transform(exp(-a*sqrt(x))*cos(a*sqrt(x)), x, k)
a*exp(-a**2/(2*k))/(2*k**(3/2))
class sympy.integrals.transforms.CosineTransform(*args)[源代码]#

类表示未赋值的余弦变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算余弦变换的信息,请参见 cosine_transform() 文档字符串。

sympy.integrals.transforms.inverse_cosine_transform(F, k, x, **hints)[源代码]#

计算 \(F\) ,定义为

\[f(x)=\sqrt{\frac{2}{\pi}\int{0}}\infty f(k)\cos(2\pi x k)\mathrm{d}k。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 InverseCosineTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import inverse_cosine_transform, sqrt, pi
>>> from sympy.abc import x, k, a
>>> inverse_cosine_transform(sqrt(2)*a/(sqrt(pi)*(a**2 + k**2)), k, x)
exp(-a*x)
>>> inverse_cosine_transform(1/sqrt(k), k, x)
1/sqrt(x)
class sympy.integrals.transforms.InverseCosineTransform(*args)[源代码]#

表示未赋值的类的反变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算反余弦变换,请参见 inverse_cosine_transform() 文档字符串。

sympy.integrals.transforms.hankel_transform(f, r, k, nu, **hints)[源代码]#

计算 \(f\) ,定义为

\[F\nu(k)=\int{0}^\infty F(r)J\nu(kr)r\mathrm{d}r。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 HankelTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import hankel_transform, inverse_hankel_transform
>>> from sympy import exp
>>> from sympy.abc import r, k, m, nu, a
>>> ht = hankel_transform(1/r**m, r, k, nu)
>>> ht
2*k**(m - 2)*gamma(-m/2 + nu/2 + 1)/(2**m*gamma(m/2 + nu/2))
>>> inverse_hankel_transform(ht, k, r, nu)
r**(-m)
>>> ht = hankel_transform(exp(-a*r), r, k, 0)
>>> ht
a/(k**3*(a**2/k**2 + 1)**(3/2))
>>> inverse_hankel_transform(ht, k, r, 0)
exp(-a*r)
class sympy.integrals.transforms.HankelTransform(*args)[源代码]#

类表示未赋值的Hankel转换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算Hankel变换的信息,请参见 hankel_transform() 文档字符串。

sympy.integrals.transforms.inverse_hankel_transform(F, k, r, nu, **hints)[源代码]#

求逆Hankel变换 \(F\) 定义为

\[f(r)=\int{0}^\infty f\nu(k)J\nu(kr)k\mathrm{d}k。\]

解释

如果无法以闭合形式计算转换,则此函数将返回未赋值的 InverseHankelTransform 对象。

有关可能的提示的说明,请参阅的docstring sympy.integrals.transforms.IntegralTransform.doit() . 请注意,对于此转换,默认情况下 noconds=True .

实例

>>> from sympy import hankel_transform, inverse_hankel_transform
>>> from sympy import exp
>>> from sympy.abc import r, k, m, nu, a
>>> ht = hankel_transform(1/r**m, r, k, nu)
>>> ht
2*k**(m - 2)*gamma(-m/2 + nu/2 + 1)/(2**m*gamma(m/2 + nu/2))
>>> inverse_hankel_transform(ht, k, r, nu)
r**(-m)
>>> ht = hankel_transform(exp(-a*r), r, k, 0)
>>> ht
a/(k**3*(a**2/k**2 + 1)**(3/2))
>>> inverse_hankel_transform(ht, k, r, 0)
exp(-a*r)
class sympy.integrals.transforms.InverseHankelTransform(*args)[源代码]#

类表示未赋值的反向Hankel变换。

有关此类的用法,请参见 IntegralTransform 文档字符串。

有关如何计算逆Hankel变换的信息,请参见 inverse_hankel_transform() 文档字符串。

class sympy.integrals.transforms.IntegralTransform(*args)[源代码]#

整型变换的基类。

解释

此类表示未赋值的转换。

若要实现具体的转换,请从该类派生并实现 _compute_transform(f, x, s, **hints)_as_integral(f, x, s) 功能。如果无法计算变换,请升高 IntegralTransformError .

同时设置 cls._name . 例如,

>>> from sympy import LaplaceTransform
>>> LaplaceTransform._name
'Laplace'

实施 self._collapse_extra 如果您的函数返回的不仅仅是一个数字,还可能返回一个收敛条件。

doit(**hints)[源代码]#

尝试以闭合形式计算转换。

解释

这个通用函数处理线性度,但除此之外,几乎所有的事情都要交给计算转换。

标准提示如下:

  • simplify :是否简化结果

  • noconds: if True, do not return convergence conditions

  • needeval :如果为True,则引发IntegralTransformError而不是

    返回IntegralTransform对象

这些提示的默认值取决于具体的转换,通常默认值是 (simplify, noconds, needeval) = (True, False, False) .

property function#

要转换的函数。

property function_variable#

要转换的函数的因变量。

property transform_variable#

独立变换变量。

exception sympy.integrals.transforms.IntegralTransformError(transform, function, msg)[源代码]#

与计算转换问题有关的异常。

解释

此类主要用于内部;如果无法计算积分,则通常返回表示未赋值转换的对象。

暗示 needeval=True 可用于禁用返回的转换对象,并在无法计算积分时引发此异常。

内构件#

SymPy使用许多算法来计算积分。算法按顺序进行试验,直到得到答案。这些算法中的大多数都可以使用各种标志手动启用或禁用 integrate()doit() .

SymPy首先应用了几种启发式算法,因为这些算法最快:

  1. 如果函数是有理函数,则有一个完整的算法来集成有理函数,称为Lazard Rioboo Trager和Horowitz-Ostrogradsky算法。它们在中实现 ratint() .

    sympy.integrals.rationaltools.ratint(f, x, **flags)[源代码]#

    执行有理函数的不定积分。

    解释

    给定一个字段 \(K\) 和一个有理函数 \(f = p/q\) 在哪里 \(p\)\(q\) 多项式在吗 \(K[x]\) ,返回函数 \(g\) 这样的话 \(f = g'\) .

    实例

    >>> from sympy.integrals.rationaltools import ratint
    >>> from sympy.abc import x
    
    >>> ratint(36/(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2), x)
    (12*x + 6)/(x**2 - 1) + 4*log(x - 2) - 4*log(x + 1)
    

    工具书类

    [R568]

    M、 布朗斯坦,《符号整合I:超越功能》,第二版,斯普林格·韦拉格,2005年,第35-70页

    sympy.integrals.rationaltools.ratint_ratpart(f, g, x)[源代码]#

    Horowitz-Ostrogradsky算法。

    解释

    给定一个域K和K中的多项式f和g [x] ,使得f和g是互质的并且deg(f)<deg(g),返回K(x)中的分数A和B,使得f/g=A'+B并且B具有无平方分母。

    实例

    >>> from sympy.integrals.rationaltools import ratint_ratpart
    >>> from sympy.abc import x, y
    >>> from sympy import Poly
    >>> ratint_ratpart(Poly(1, x, domain='ZZ'),
    ... Poly(x + 1, x, domain='ZZ'), x)
    (0, 1/(x + 1))
    >>> ratint_ratpart(Poly(1, x, domain='EX'),
    ... Poly(x**2 + y**2, x, domain='EX'), x)
    (0, 1/(x**2 + y**2))
    >>> ratint_ratpart(Poly(36, x, domain='ZZ'),
    ... Poly(x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2, x, domain='ZZ'), x)
    ((12*x + 6)/(x**2 - 1), 12/(x**2 - x - 2))
    
    sympy.integrals.rationaltools.ratint_logpart(f, g, x, t=None)[源代码]#

    Lazard Rioboo-Trager算法。

    解释

    给定一个域K和K中的多项式f和g [x] ,使得f和g是互质的,deg(f)<deg(g)并且g是无平方的,则返回多项式元组(s_i,q_i)的列表,对于i=1..n,这样s_i在K中 [t, x] 和q逖i in K [t] ,以及:

              ___    ___
    d  f   d  \  `   \  `
    -- - = --  )      )   a log(s_i(a, x))
    dx g   dx /__,   /__,
             i=1..n a | q_i(a) = 0
    

    实例

    >>> from sympy.integrals.rationaltools import ratint_logpart
    >>> from sympy.abc import x
    >>> from sympy import Poly
    >>> ratint_logpart(Poly(1, x, domain='ZZ'),
    ... Poly(x**2 + x + 1, x, domain='ZZ'), x)
    [(Poly(x + 3*_t/2 + 1/2, x, domain='QQ[_t]'),
    ...Poly(3*_t**2 + 1, _t, domain='ZZ'))]
    >>> ratint_logpart(Poly(12, x, domain='ZZ'),
    ... Poly(x**2 - x - 2, x, domain='ZZ'), x)
    [(Poly(x - 3*_t/8 - 1/2, x, domain='QQ[_t]'),
    ...Poly(-_t**2 + 16, _t, domain='ZZ'))]
    
  2. trigintegrate() 用模式匹配求解三角函数的积分

    sympy.integrals.trigonometry.trigintegrate(f, x, conds='piecewise')[源代码]#

    Integrate f = Mul(trig) over x.

    实例

    >>> from sympy import sin, cos, tan, sec
    >>> from sympy.integrals.trigonometry import trigintegrate
    >>> from sympy.abc import x
    
    >>> trigintegrate(sin(x)*cos(x), x)
    sin(x)**2/2
    
    >>> trigintegrate(sin(x)**2, x)
    x/2 - sin(x)*cos(x)/2
    
    >>> trigintegrate(tan(x)*sec(x), x)
    1/cos(x)
    
    >>> trigintegrate(sin(x)*tan(x), x)
    -log(sin(x) - 1)/2 + log(sin(x) + 1)/2 - sin(x)
    

    工具书类

  3. deltaintegrate() 用解积分 DiracDelta 物体。

    sympy.integrals.deltafunctions.deltaintegrate(f, x)[源代码]#

    解释

    整合的理念如下:

    • 如果我们处理的是DiracDelta表达式,即DiracDelta(g(x)),我们试图简化它。

      如果我们可以简化它,那么我们将得到的表达式进行积分。我们已经知道我们可以集成一个简化的表达式,因为只涉及简单的DiracDelta表达式。

      如果我们不能简化,有两种情况:

      1. 这个表达式是一个简单的表达式:我们返回积分,在处理导数或适当的DiracDelta时要小心。

      2. 这个表达式并不简单(即DiracDelta(cos(x)):我们什么也做不了。

    • 如果节点是具有DiracDelta项的乘法节点:

      首先我们扩展它。

      如果扩张真的起作用,那么我们就试着整合扩张。

      如果没有,我们尝试提取一个简单的DiracDelta项,则有两种情况:

      1. 我们有一个简单的DiracDelta项,所以我们返回积分。

      2. 我们没有一个简单的项,但是我们有一个带有简化DiracDelta项的表达式,所以我们将这个表达式积分。

    实例

    >>> from sympy.abc import x, y, z
    >>> from sympy.integrals.deltafunctions import deltaintegrate
    >>> from sympy import sin, cos, DiracDelta
    >>> deltaintegrate(x*sin(x)*cos(x)*DiracDelta(x - 1), x)
    sin(1)*cos(1)*Heaviside(x - 1)
    >>> deltaintegrate(y**2*DiracDelta(x - z)*DiracDelta(y - z), y)
    z**2*DiracDelta(x - z)*Heaviside(y - z)
    
  4. singularityintegrate() is applied if the function contains a SingularityFunction

    sympy.integrals.singularityfunctions.singularityintegrate(f, x)[源代码]#

    这个函数处理奇异函数的不定积分。这个 integrate 每当SingularityFunction的实例作为参数传递时,函数在内部调用此函数。

    解释

    整合的理念如下:

    • 如果我们处理的是一个奇异函数表达式,即。 SingularityFunction(x, a, n) ,我们就回来 SingularityFunction(x, a, n + 1)/(n + 1) 如果 n >= 0SingularityFunction(x, a, n + 1) 如果 n < 0 .

    • 如果节点是一个具有奇异函数项的乘法或幂次节点,我们用Heaviside和DiracDelta重写整个表达式,然后对输出进行积分。最后,我们用奇异函数重写积分的输出。

    • 如果没有出现上述情况,我们将不返回任何情况。

    实例

    >>> from sympy.integrals.singularityfunctions import singularityintegrate
    >>> from sympy import SingularityFunction, symbols, Function
    >>> x, a, n, y = symbols('x a n y')
    >>> f = Function('f')
    >>> singularityintegrate(SingularityFunction(x, a, 3), x)
    SingularityFunction(x, a, 4)/4
    >>> singularityintegrate(5*SingularityFunction(x, 5, -2), x)
    5*SingularityFunction(x, 5, -1)
    >>> singularityintegrate(6*SingularityFunction(x, 5, -1), x)
    6*SingularityFunction(x, 5, 0)
    >>> singularityintegrate(x*SingularityFunction(x, 0, -1), x)
    0
    >>> singularityintegrate(SingularityFunction(x, 1, -1) * f(x), x)
    f(1)*SingularityFunction(x, 1, 0)
    
  5. 如果不能应用启发式算法, risch_integrate() 下一步就要审判了。这个 Risch算法 是计算初等函数反导数的一般方法。Risch算法是一个决策过程,可以确定是否存在一个基本解,并在这种情况下计算它。它可以扩展到处理除基本函数外的许多非基本函数。然而,在SymPy中实现的版本只支持完整算法的一小部分,特别是在部分超越算法上实现了指数和对数。优点 risch_integrate() 与其他方法相比,如果它返回 NonElementaryIntegral ,该算法证明了积分是非元素的,这意味着积分不能用指数、对数、三角函数、幂、有理函数、代数函数和函数组合的组合来表示。

    sympy.integrals.risch.risch_integrate(f, x, extension=None, handle_first='log', separate_integral=False, rewrite_complex=None, conds='piecewise')[源代码]#

    Risch积分算法。

    解释

    只支持超越函数。目前,只支持指数和对数,但对三角函数的支持即将到来。

    如果此函数在结果中返回未赋值的积分,则意味着它已证明该积分是非元素的。任何错误都将导致引发NotImplementedError。未赋值的积分将是非元素Integral的一个实例,它是Integral的一个子类。

    handle_first可以是“exp”或“log”。这会改变扩展的构建顺序,并可能导致不同的(但等效的)解决方案(关于这方面的示例,请参阅5109版)。也有可能是用一个而不是另一个来计算积分,因为并不是所有的情况都已经实现了。它默认为'log',这样外部扩展在可能的情况下是指数的,因为更多的指数情况已经实现。

    If separate_integral is True, the result is returned as a tuple (ans, i), where the integral is ans + i, ans is elementary, and i is either a NonElementaryIntegral or 0. This useful if you want to try further integrating the NonElementaryIntegral part using other algorithms to possibly get a solution in terms of special functions. It is False by default.

    实例

    >>> from sympy.integrals.risch import risch_integrate
    >>> from sympy import exp, log, pprint
    >>> from sympy.abc import x
    

    首先,我们尝试积分exp(-x**2)。除了常数因子2/sqrt(pi),这是著名的误差函数。

    >>> pprint(risch_integrate(exp(-x**2), x))
      /
     |
     |    2
     |  -x
     | e    dx
     |
    /
    

    结果中的未赋值积分意味着risch_integrate()已经证明exp(-x**2)没有初等反导数。

    在许多情况下,risch_integrate()可以将基本的反导数部分从非基本的反导数部分中分离出来。例如,

    >>> pprint(risch_integrate((2*log(x)**2 - log(x) - x**2)/(log(x)**3 -
    ... x**2*log(x)), x))
                                             /
                                            |
      log(-x + log(x))   log(x + log(x))    |   1
    - ---------------- + --------------- +  | ------ dx
             2                  2           | log(x)
                                            |
                                           /
    

    这意味着它已经证明了1/log(x)的积分是非元素的。这个函数也称为对数积分,通常表示为Li(x)。

    risch_integrate()目前只接受纯超越函数的指数和对数,但请注意,这可以包括嵌套的指数和对数,以及除E以外的基数的指数。

    >>> pprint(risch_integrate(exp(x)*exp(exp(x)), x))
     / x\
     \e /
    e
    >>> pprint(risch_integrate(exp(exp(x)), x))
      /
     |
     |  / x\
     |  \e /
     | e     dx
     |
    /
    
    >>> pprint(risch_integrate(x*x**x*log(x) + x**x + x*x**x, x))
       x
    x*x
    >>> pprint(risch_integrate(x**x, x))
      /
     |
     |  x
     | x  dx
     |
    /
    
    >>> pprint(risch_integrate(-1/(x*log(x)*log(log(x))**2), x))
         1
    -----------
    log(log(x))
    
    class sympy.integrals.risch.NonElementaryIntegral(function, *symbols, **assumptions)[源代码]#

    表示非元素积分。

    解释

    如果integrate()的结果是此类的实例,则保证它是非元素的。请注意,默认情况下integrate()将尝试寻找任何封闭形式的解决方案,即使是对于本身可能不是基本函数的特殊函数也是如此。要使integrate()只给出基本解,或者在它可以证明积分是非元素的情况下,使用integrate(risch=True)。在这种情况下,integrate()可能会引发NotImplementedError,如果它不能做出这样的判断。

    integrate()使用确定性Risch算法来积分初等函数或证明它们没有初等积分。在某些情况下,该算法可以将一个积分分为初等和非初等两部分,这样积分的结果就是一个初等表达式和一个非初等积分的和。

    实例

    >>> from sympy import integrate, exp, log, Integral
    >>> from sympy.abc import x
    
    >>> a = integrate(exp(-x**2), x, risch=True)
    >>> print(a)
    Integral(exp(-x**2), x)
    >>> type(a)
    <class 'sympy.integrals.risch.NonElementaryIntegral'>
    
    >>> expr = (2*log(x)**2 - log(x) - x**2)/(log(x)**3 - x**2*log(x))
    >>> b = integrate(expr, x, risch=True)
    >>> print(b)
    -log(-x + log(x))/2 + log(x + log(x))/2 + Integral(1/log(x), x)
    >>> type(b.atoms(Integral).pop())
    <class 'sympy.integrals.risch.NonElementaryIntegral'>
    
  6. 对于非初等定积分,SymPy使用所谓的Meijer G函数。有关详细信息,请参见 用Meijer G函数计算积分 .

  7. 到目前为止提到的所有算法要么是基于模式匹配的启发式算法,要么是使用与大多数人在微积分课程中学习的方法有很大不同的算法来求解积分。SymPy还实现了一种方法,它可以用与微积分学基本相同的方式来求解积分。这种方法的优点是可以从中提取积分步数,这样就可以知道如何“手工”计算积分。这是由 SymPy Gamma . 这在 manualintegrate() 功能。积分的步骤可以用 integral_steps() 功能。

    sympy.integrals.manualintegrate.manualintegrate(f, var)[源代码]#

    解释

    使用一种类似于学生手工操作的算法计算单个变量的不定积分。

    不像 integrate() ,var只能是单个符号。

    实例

    >>> from sympy import sin, cos, tan, exp, log, integrate
    >>> from sympy.integrals.manualintegrate import manualintegrate
    >>> from sympy.abc import x
    >>> manualintegrate(1 / x, x)
    log(x)
    >>> integrate(1/x)
    log(x)
    >>> manualintegrate(log(x), x)
    x*log(x) - x
    >>> integrate(log(x))
    x*log(x) - x
    >>> manualintegrate(exp(x) / (1 + exp(2 * x)), x)
    atan(exp(x))
    >>> integrate(exp(x) / (1 + exp(2 * x)))
    RootSum(4*_z**2 + 1, Lambda(_i, _i*log(2*_i + exp(x))))
    >>> manualintegrate(cos(x)**4 * sin(x), x)
    -cos(x)**5/5
    >>> integrate(cos(x)**4 * sin(x), x)
    -cos(x)**5/5
    >>> manualintegrate(cos(x)**4 * sin(x)**3, x)
    cos(x)**7/7 - cos(x)**5/5
    >>> integrate(cos(x)**4 * sin(x)**3, x)
    cos(x)**7/7 - cos(x)**5/5
    >>> manualintegrate(tan(x), x)
    -log(cos(x))
    >>> integrate(tan(x), x)
    -log(cos(x))
    
    sympy.integrals.manualintegrate.integral_steps(integrand, symbol, **options)[源代码]#

    返回计算积分所需的步骤。

    返回:

    rule : Rule

    第一步;大多数规则都有必须考虑的子步骤。这些子步骤可以用 manualintegrate 获得结果。

    解释

    这个功能试图尽可能地反映学生的手操作。

    SymPy Gamma使用它来逐步解释积分。它用来格式化此函数结果的代码可以在https://github.com/sympy/sympy_gamma/blob/master/app/logic/intsteps.py。

    实例

    >>> from sympy import exp, sin
    >>> from sympy.integrals.manualintegrate import integral_steps
    >>> from sympy.abc import x
    >>> print(repr(integral_steps(exp(x) / (1 + exp(2 * x)), x)))     
    URule(integrand=exp(x)/(exp(2*x) + 1), variable=x, u_var=_u, u_func=exp(x),
    substep=ArctanRule(integrand=1/(_u**2 + 1), variable=_u, a=1, b=1, c=1))
    >>> print(repr(integral_steps(sin(x), x)))     
    SinRule(integrand=sin(x), variable=x)
    >>> print(repr(integral_steps((x**2 + 3)**2, x)))     
    RewriteRule(integrand=(x**2 + 3)**2, variable=x, rewritten=x**4 + 6*x**2 + 9,
    substep=AddRule(integrand=x**4 + 6*x**2 + 9, variable=x,
    substeps=[PowerRule(integrand=x**4, variable=x, base=x, exp=4),
    ConstantTimesRule(integrand=6*x**2, variable=x, constant=6, other=x**2,
    substep=PowerRule(integrand=x**2, variable=x, base=x, exp=2)),
    ConstantRule(integrand=9, variable=x)]))
    
  8. 最后,如果以上所有方法都失败了,SymPy还使用了一个简化的Risch算法,称为 Risch-Norman algorithm . 由于计算速度最慢,所以最后尝试了该算法。此功能在 heurisch()

    sympy.integrals.heurisch.heurisch(f, x, rewrite=False, hints=None, mappings=None, retries=3, degree_offset=0, unnecessary_permutations=None, _try_heurisch=None)[源代码]#

    用启发式Risch算法计算不定积分。

    解释

    这是一种基于manuelbronstein的“穷人积分器”的扩展启发式(并行)Risch算法的启发式方法。

    该算法支持各种类型的函数,包括超越初等函数或特殊函数,如Airy、Bessel、Whittaker和Lambert。

    请注意,此算法不是一个决策过程。如果它不能计算给定函数的反导数,那么这并不能证明这样的函数不存在。在这种情况下,应该使用递归Risch算法。这个算法是否能成为一个完整的决策过程是一个悬而未决的问题。

    This is an internal integrator procedure. You should use top level 'integrate' function in most cases, as this procedure needs some preprocessing steps and otherwise may fail.

    规范

    启发式(f,x,重写=False,提示=None)

    在哪里?

    f:表达式x:符号

    重写->根据“tan”和“tanh”提示强制重写“f”->反导数中可能出现的函数列表

    • 提示=无-->根本没有建议

    • 提示= [ ] -->试着弄清楚

    • 提示= [f1,…,fn] -->我们更清楚

    实例

    >>> from sympy import tan
    >>> from sympy.integrals.heurisch import heurisch
    >>> from sympy.abc import x, y
    
    >>> heurisch(y*tan(x), x)
    y*log(tan(x)**2 + 1)/2
    

    参见曼努埃尔·布朗斯坦的《穷人的集成商》:

    工具书类

    有关已实现算法的更多信息,请参阅:

    [R571]

    K. Geddes, L. Stefanus, On the Risch-Norman Integration Method and its Implementation in Maple, Proceedings of ISSAC'89, ACM Press, 212-217.

    [R572]

    J. H. Davenport, On the Parallel Risch Algorithm (I), Proceedings of EUROCAM'82, LNCS 144, Springer, 144-157.

    [R573]

    J. H. Davenport, On the Parallel Risch Algorithm (III): Use of Tangents, SIGSAM Bulletin 16 (1982), 3-6.

    [R574]

    J. H. Davenport, B. M. Trager, On the Parallel Risch Algorithm (II), ACM Transactions on Mathematical Software 11 (1985), 356-362.

    sympy.integrals.heurisch.components(f, x)[源代码]#

    返回给定表达式的所有函数组件的集合,其中包括符号、函数应用程序和组合以及非整数幂。分数次幂用最小的正指数收集。

    实例

    >>> from sympy import cos, sin
    >>> from sympy.abc import x
    >>> from sympy.integrals.heurisch import components
    
    >>> components(sin(x)*cos(x)**2, x)
    {x, sin(x), cos(x)}
    

    参见

    heurisch

API引用#

sympy.integrals.integrals.integrate(f, var, ...)[源代码]#

自 1.6 版本弃用: Using integrate() with Poly is deprecated. Use Poly.integrate() instead. See Using integrate with Poly.

解释

用Risch-Norman算法和查表法计算一个或多个变量的定积分或不定积分。这个程序可以处理初等代数函数和超越函数,也可以处理大量的特殊函数,包括Airy、Bessel、Whittaker和Lambert。

var可以是:

  • 符号——不定积分

  • 元组(符号,a)——带结果的不定积分

    given with a replacing symbol

  • 元组(符号,a,b)——定积分

可以指定几个变量,在这种情况下,结果是多重积分。(如果省略var且被积函数为单变量,则对该变量进行不定积分。)

不定积分返回时不带独立于积分变量的项。(见示例)

定的广义积分往往需要精确的收敛条件。传递conds='pieclewise'、'separate'或'none',分别将它们作为分段函数返回,作为单独的结果(即结果将是一个元组),或者根本不返回(默认值为“pieclewise”)。

Strategy

SymPy使用各种方法来确定积分。一种方法是求被积函数的反导数,然后利用微积分的基本定理。各种函数被实现来集成多项式、有理函数和三角函数,以及包含DiracDelta项的被积函数。

SymPy还实现了Risch算法的一部分,这是一个集成基本函数的决策过程,即该算法既可以找到一个初等反导数,也可以证明它不存在。还有一个(非常成功,尽管有点慢)的启发式Risch算法的一般实现。随着更多完整的Risch算法的实现,这种算法最终将被淘汰。有关使用代数方法计算反导数的详细信息,请参见Integral.u eval_Integral()的docstring。

选项risch=True可用于仅使用(完整)risch算法。如果你想知道一个初等函数是否有一个初等反导数,这是很有用的。如果这个函数返回的不定积分是非元素Integral的一个实例,这意味着Risch算法已经证明了该积分是非初等的。注意,在默认情况下,额外的方法(如下面概述的Meijer G方法)会在这些积分上尝试,因为它们可以用特殊函数表示,所以如果你只关心基本的答案,就使用risch=True。还请注意,由该函数返回的未赋值积分不一定是非元素积分,即使risch=True,因为这可能只是一个迹象,表明需要积分该函数的risch算法的特定部分尚未实现。

另一个策略家族来自于根据所谓的Meijer G函数重新编写被积函数。一个G函数的不定积分总是可以计算的,两个G函数乘积的定积分可以从零到无穷大计算。我们实现了各种策略来将被积函数重写为G函数,并使用这些信息来计算积分(参见 meijerint 模块)。

manual=True选项可用于仅使用尝试手动模拟积分的算法。此算法不像其他算法那样处理被积函数,但可能以更熟悉的形式返回结果。这个 manualintegrate 模块具有返回所用步骤的函数(有关详细信息,请参阅模块docstring)。

一般来说,代数方法最适用于计算初等函数(可能很复杂)组合的反导数。G函数法最适用于计算中等复杂的特殊函数组合从零到无穷大的定积分,或非常简单的特殊函数组合的不定积分。

集成代码采用的策略如下:

  • 如果计算一个定积分,并且两个极限都是实的,并且至少有一个极限是+-oo,请先尝试定积分的G函数方法。

  • 尝试找到一个反导数,使用所有可用的方法,按性能排序(即首先尝试最快的方法,最后尝试最慢的方法;尤其是首先尝试多项式积分,其次是Meijer G函数,最后是启发式Risch)。

  • 如果仍然不成功,尝试G-函数而不考虑限制。

选项meijerg=True,False,None可分别用于:始终使用G函数方法而不使用其他方法,从不使用G函数方法,或使用所有可用方法(按上述顺序)。默认为“无”。

实例

>>> from sympy import integrate, log, exp, oo
>>> from sympy.abc import a, x, y
>>> integrate(x*y, x)
x**2*y/2
>>> integrate(log(x), x)
x*log(x) - x
>>> integrate(log(x), (x, 1, a))
a*log(a) - a + 1
>>> integrate(x)
x**2/2

与x无关的项通过不定积分被删除:

>>> from sympy import sqrt
>>> integrate(sqrt(1 + x), (x, 0, x))
2*(x + 1)**(3/2)/3 - 2/3
>>> integrate(sqrt(1 + x), x)
2*(x + 1)**(3/2)/3
>>> integrate(x*y)
Traceback (most recent call last):
...
ValueError: specify integration variables to integrate x*y

注意 integrate(x) 语法只是为了方便交互会话,在库代码中应该避免使用。

>>> integrate(x**a*exp(-x), (x, 0, oo)) # same as conds='piecewise'
Piecewise((gamma(a + 1), re(a) > -1),
    (Integral(x**a*exp(-x), (x, 0, oo)), True))
>>> integrate(x**a*exp(-x), (x, 0, oo), conds='none')
gamma(a + 1)
>>> integrate(x**a*exp(-x), (x, 0, oo), conds='separate')
(gamma(a + 1), re(a) > -1)
sympy.integrals.integrals.line_integrate(field, Curve, variables)[源代码]#

计算线积分。

实例

>>> from sympy import Curve, line_integrate, E, ln
>>> from sympy.abc import x, y, t
>>> C = Curve([E**t + 1, E**t - 1], (t, 0, ln(2)))
>>> line_integrate(x + y, C, [x, y])
3*sqrt(2)

班级 Integral 表示未赋值的积分,并具有一些有助于表达式积分的方法。

class sympy.integrals.integrals.Integral(function, *symbols, **assumptions)[源代码]#

表示未赋值的积分。

is_commutative#

返回整数中的所有自由符号是否可交换。

as_sum(n=None, method='midpoint', evaluate=True)[源代码]#

用和近似定积分。

参数:

n :

要使用的子间隔数,可选。

method :

“左”、“右”、“中点”、“梯形”之一。

评价 布尔

如果为False,则返回未赋值的和表达式。默认值为True,计算总和。

笔记

这些近似积分的方法如中所述 [1] .

实例

>>> from sympy import Integral, sin, sqrt
>>> from sympy.abc import x, n
>>> e = Integral(sin(x), (x, 3, 7))
>>> e
Integral(sin(x), (x, 3, 7))

出于演示目的,此间隔将仅分为两个区域,以 [3, 5] 和 [5, 7] .

左侧规则在每个间隔的左侧使用函数求值:

>>> e.as_sum(2, 'left')
2*sin(5) + 2*sin(3)

中点规则在每个间隔的中心使用求值:

>>> e.as_sum(2, 'midpoint')
2*sin(4) + 2*sin(6)

右侧规则在每个间隔的右侧使用函数评估:

>>> e.as_sum(2, 'right')
2*sin(5) + 2*sin(7)

梯形规则在区间两边使用函数求值。这相当于取左右手规则结果的平均值:

>>> e.as_sum(2, 'trapezoid')
2*sin(5) + sin(3) + sin(7)
>>> (e.as_sum(2, 'left') + e.as_sum(2, 'right'))/2 == _
True

这里,x=0处的不连续可以通过使用中点或右手方法来避免:

>>> e = Integral(1/sqrt(x), (x, 0, 1))
>>> e.as_sum(5).n(4)
1.730
>>> e.as_sum(10).n(4)
1.809
>>> e.doit().n(4)  # the actual value is 2
2.000

左或梯形方法将遇到不连续并返回无穷大:

>>> e.as_sum(5, 'left')
zoo

间隔的数量可以是符号。如果省略,将使用虚拟符号。

>>> e = Integral(x**2, (x, 0, 2))
>>> e.as_sum(n, 'right').expand()
8/3 + 4/n + 4/(3*n**2)

这表明中点规则更精确,因为其误差项随着n的平方衰减:

>>> e.as_sum(method='midpoint').expand()
8/3 - 2/(3*_n**2)

返回带有evaluate=False的符号和:

>>> e.as_sum(n, 'midpoint', evaluate=False)
2*Sum((2*_k/n - 1/n)**2, (_k, 1, n))/n

参见

Integral.doit

使用任何提示执行集成

工具书类

doit(**hints)[源代码]#

使用给出的任何提示执行集成。

实例

>>> from sympy import Piecewise, S
>>> from sympy.abc import x, t
>>> p = x**2 + Piecewise((0, x/t < 0), (1, True))
>>> p.integrate((t, S(4)/5, 1), (x, -1, 1))
1/3
property free_symbols#

此方法返回在计算积分时将存在的符号。如果您试图确定积分是否依赖于某个符号,这将非常有用。

实例

>>> from sympy import Integral
>>> from sympy.abc import x, y
>>> Integral(x, (x, y, 1)).free_symbols
{y}
principal_value(**kwargs)[源代码]#

Compute the Cauchy Principal Value of the definite integral of a real function in the given interval on the real axis.

解释

In mathematics, the Cauchy principal value, is a method for assigning values to certain improper integrals which would otherwise be undefined.

实例

>>> from sympy import Integral, oo
>>> from sympy.abc import x
>>> Integral(x+1, (x, -oo, oo)).principal_value()
oo
>>> f = 1 / (x**3)
>>> Integral(f, (x, -oo, oo)).principal_value()
0
>>> Integral(f, (x, -10, 10)).principal_value()
0
>>> Integral(f, (x, -10, oo)).principal_value() + Integral(f, (x, -oo, 10)).principal_value()
0

工具书类

transform(x, u)[源代码]#

执行变量更改 \(x\)\(u\) 使用 \(x\)\(u\) 它将定义转换 \(f\)\(F\) (彼此相反)如下:

  1. 如果 \(x\) 是一个符号(它是积分的一个变量)那么 \(u\) 将被解释为某个函数,f(u),具有逆f(u)。这实际上就是用f(x)代替x。

  2. 如果 \(u\) 是一个符号吗 \(x\) 将被解释为某个函数,F(x),具有逆F(u)。这通常被称为u-取代。

一旦确定了f和f,转换如下:

\[\inta^b x\mathrm{d}x\rightarrow\int{F(a)}^{F(b)}F(x)\]

在哪里? \(F(x)\) 是的反义词 \(f(x)\) 并对极限和被积函数进行了修正,使积分后的值保持不变。

笔记

The mappings, F(x) or f(u), must lead to a unique integral. Linear or rational linear expression, 2*x, 1/x and sqrt(x), will always work; quadratic expressions like x**2 - 1 are acceptable as long as the resulting integrand does not depend on the sign of the solutions (see examples).

The integral will be returned unchanged if x is not a variable of integration.

x must be (or contain) only one of of the integration variables. If u has more than one free symbol then it should be sent as a tuple (u, uvar) where uvar identifies which variable is replacing the integration variable. XXX can it contain another integration variable?

实例

>>> from sympy.abc import a, x, u
>>> from sympy import Integral, cos, sqrt
>>> i = Integral(x*cos(x**2 - 1), (x, 0, 1))

变换可以改变积分的变量

>>> i.transform(x, u)
Integral(u*cos(u**2 - 1), (u, 0, 1))

只要得到唯一的被积函数,变换就可以进行u-代换:

>>> i.transform(x**2 - 1, u)
Integral(cos(u)/2, (u, -1, 0))

此尝试失败,因为x=+/-sqrt(u+1)并且符号没有从被积函数中取消:

>>> Integral(cos(x**2 - 1), (x, 0, 1)).transform(x**2 - 1, u)
Traceback (most recent call last):
...
ValueError:
The mapping between F(x) and f(u) did not give a unique integrand.

转换可以进行替换。这里,使用“u-替换”将先前的结果转换回原始表达式:

>>> ui = _
>>> _.transform(sqrt(u + 1), x) == i
True

我们可以通过常规替换来实现同样的效果:

>>> ui.transform(u, x**2 - 1) == i
True

如果 \(x\) 不包含积分符号,则积分将原封不动地返回。完整的 \(i\) 没有集成变量 \(a\) 所以不会有任何改变:

>>> i.transform(a, x) == i
True

什么时候? \(u\) 有多个可用符号要替换的符号 \(x\) 必须通过路过来识别 \(u\) 作为元组:

>>> Integral(x, (x, 0, 1)).transform(x, (u + a, u))
Integral(a + u, (u, -a, 1 - a))
>>> Integral(x, (x, 0, 1)).transform(x, (u + a, a))
Integral(a + u, (a, -u, 1 - u))

参见

sympy.concrete.expr_with_limits.ExprWithLimits.variables

列出积分变量

as_dummy

用虚拟变量替换积分变量

Integral 子类来自 ExprWithLimits 一个普通的超类 IntegralSum .

class sympy.concrete.expr_with_limits.ExprWithLimits(function, *symbols, **assumptions)[源代码]#
property bound_symbols#

只返回伪变量的变量。

实例

>>> from sympy import Integral
>>> from sympy.abc import x, i, j, k
>>> Integral(x**i, (i, 1, 3), (j, 2), k).bound_symbols
[i, j]

参见

function, limits, free_symbols

as_dummy

重命名伪变量

sympy.integrals.integrals.Integral.transform

对虚拟变量执行映射

property free_symbols#

此方法返回对象中的符号,不包括具有特定值的符号(即伪符号)。

实例

>>> from sympy import Sum
>>> from sympy.abc import x, y
>>> Sum(x, (x, y, 1)).free_symbols
{y}
property function#

返回跨限制应用的函数。

实例

>>> from sympy import Integral
>>> from sympy.abc import x
>>> Integral(x**2, (x,)).function
x**2
property has_finite_limits#

如果已知限制是有限的,则返回True(通过显式边界、边界上的假设或变量的假设)。如果已知无穷大,则为False,基于边界。如果没有足够的信息可供确定,则无。

实例

>>> from sympy import Sum, Integral, Product, oo, Symbol
>>> x = Symbol('x')
>>> Sum(x, (x, 1, 8)).has_finite_limits
True
>>> Integral(x, (x, 1, oo)).has_finite_limits
False
>>> M = Symbol('M')
>>> Sum(x, (x, 1, M)).has_finite_limits
>>> N = Symbol('N', integer=True)
>>> Product(x, (x, 1, N)).has_finite_limits
True
property has_reversed_limits#

如果已知限制的顺序与显式边界、边界上的假设或变量的假设顺序相反,则返回True。如果已知为正常顺序,则为False,基于边界。如果没有足够的信息可供确定,则无。

实例

>>> from sympy import Sum, Integral, Product, oo, Symbol
>>> x = Symbol('x')
>>> Sum(x, (x, 8, 1)).has_reversed_limits
True
>>> Sum(x, (x, 1, oo)).has_reversed_limits
False
>>> M = Symbol('M')
>>> Integral(x, (x, 1, M)).has_reversed_limits
>>> N = Symbol('N', integer=True, positive=True)
>>> Sum(x, (x, 1, N)).has_reversed_limits
False
>>> Product(x, (x, 2, N)).has_reversed_limits
>>> Product(x, (x, 2, N)).subs(N, N + 2).has_reversed_limits
False
property is_number#

如果总和没有自由符号,则返回True,否则返回False。

property limits#

返回表达式的限制。

实例

>>> from sympy import Integral
>>> from sympy.abc import x, i
>>> Integral(x**i, (i, 1, 3)).limits
((i, 1, 3),)
property variables#

返回限制变量的列表。

>>> from sympy import Sum
>>> from sympy.abc import x, i
>>> Sum(x**i, (i, 1, 3)).variables
[i]

参见

function, limits, free_symbols

as_dummy

重命名伪变量

sympy.integrals.integrals.Integral.transform

对虚拟变量执行映射

待办事项和Bugs#

还有很多函数是SymPy不知道如何集成的。有关与此模块相关的Bug,请参阅https://github.com/sympy/sympy/issues?q=is%3Aissue+is%3Aopen+标签%3aintegrams

数值积分#

SymPy具有计算任意阶和任意精度的高斯求积的点和权重的函数:

sympy.integrals.quadrature.gauss_legendre(n, n_digits)[源代码]#

Computes the Gauss-Legendre quadrature [R578] points and weights.

参数:

n :

The order of quadrature.

n_digits :

Number of significant digits of the points and weights to return.

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

高斯-勒让德求积近似于积分:

\[\整数{-1}^1f(x),dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(P_n\) 重量呢 \(w_i\) 由以下公式给出:

\[w_i=\frac{2}{\left(1-x_i^2\ right)\left(P''u n(x_i)\right)^2}\]

实例

>>> from sympy.integrals.quadrature import gauss_legendre
>>> x, w = gauss_legendre(3, 5)
>>> x
[-0.7746, 0, 0.7746]
>>> w
[0.55556, 0.88889, 0.55556]
>>> x, w = gauss_legendre(4, 5)
>>> x
[-0.86114, -0.33998, 0.33998, 0.86114]
>>> w
[0.34785, 0.65215, 0.65215, 0.34785]

工具书类

sympy.integrals.quadrature.gauss_laguerre(n, n_digits)[源代码]#

Computes the Gauss-Laguerre quadrature [R580] points and weights.

参数:

n :

The order of quadrature.

n_digits :

Number of significant digits of the points and weights to return.

返回:

(x, w) : The x and w are lists of points and weights as Floats.

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

高斯-拉盖尔求积近似于积分:

\[\整数0^{\infty}e^{-x}f(x)\,dx\大约\sum{i=1}^n w_i f(x_i)\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(L_n\) 重量呢 \(w_i\) 由以下公式给出:

\[w_i=\frac{x_i}{(n+1)^2\左(L{n+1}(x_i)\right)^2}\]

实例

>>> from sympy.integrals.quadrature import gauss_laguerre
>>> x, w = gauss_laguerre(3, 5)
>>> x
[0.41577, 2.2943, 6.2899]
>>> w
[0.71109, 0.27852, 0.010389]
>>> x, w = gauss_laguerre(6, 5)
>>> x
[0.22285, 1.1889, 2.9927, 5.7751, 9.8375, 15.983]
>>> w
[0.45896, 0.417, 0.11337, 0.010399, 0.00026102, 8.9855e-7]

工具书类

sympy.integrals.quadrature.gauss_hermite(n, n_digits)[源代码]#

Computes the Gauss-Hermite quadrature [R582] points and weights.

参数:

n :

The order of quadrature.

n_digits :

Number of significant digits of the points and weights to return.

返回:

(x, w) : The x and w are lists of points and weights as Floats.

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

高斯-埃尔米特求积近似于积分:

\[\int{-\infty}^{\infty}e^{-x^2}f(x)\,dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(H_n\) 重量呢 \(w_i\) 由以下公式给出:

\[wu i=\frac{2^{n-1}n!\sqrt{\pi}}{n^2\左(H{n-1}(x}i)\right)^2}\]

实例

>>> from sympy.integrals.quadrature import gauss_hermite
>>> x, w = gauss_hermite(3, 5)
>>> x
[-1.2247, 0, 1.2247]
>>> w
[0.29541, 1.1816, 0.29541]
>>> x, w = gauss_hermite(6, 5)
>>> x
[-2.3506, -1.3358, -0.43608, 0.43608, 1.3358, 2.3506]
>>> w
[0.00453, 0.15707, 0.72463, 0.72463, 0.15707, 0.00453]

工具书类

sympy.integrals.quadrature.gauss_gen_laguerre(n, alpha, n_digits)[源代码]#

Computes the generalized Gauss-Laguerre quadrature [R585] points and weights.

参数:

n :

The order of quadrature.

alpha :

The exponent of the singularity, \(\alpha > -1\).

n_digits :

Number of significant digits of the points and weights to return.

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

广义高斯-拉盖尔求积近似于积分:

\[\int{0}^\infty x^{\alpha}e^{-x}f(x)\,dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(L^{{\alpha}}_n\) 重量呢 \(w_i\) 由以下公式给出:

\[wu i=\frac{\Gamma(\alpha+n)}\]

实例

>>> from sympy import S
>>> from sympy.integrals.quadrature import gauss_gen_laguerre
>>> x, w = gauss_gen_laguerre(3, -S.Half, 5)
>>> x
[0.19016, 1.7845, 5.5253]
>>> w
[1.4493, 0.31413, 0.00906]
>>> x, w = gauss_gen_laguerre(4, 3*S.Half, 5)
>>> x
[0.97851, 2.9904, 6.3193, 11.712]
>>> w
[0.53087, 0.67721, 0.11895, 0.0023152]

工具书类

sympy.integrals.quadrature.gauss_chebyshev_t(n, n_digits)[源代码]#

Computes the Gauss-Chebyshev quadrature [R587] points and weights of the first kind.

参数:

n :

The order of quadrature.

n_digits :

Number of significant digits of the points and weights to return.

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

第一类高斯-切比雪夫积分近似于:

\[\int{-1}^{1}\frac{1}{\sqrt{1-x^2}}}f(x)\,dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(T_n\) 重量呢 \(w_i\) 由以下公式给出:

\[wu i=\frac{\pi}{n}\]

实例

>>> from sympy.integrals.quadrature import gauss_chebyshev_t
>>> x, w = gauss_chebyshev_t(3, 5)
>>> x
[0.86602, 0, -0.86602]
>>> w
[1.0472, 1.0472, 1.0472]
>>> x, w = gauss_chebyshev_t(6, 5)
>>> x
[0.96593, 0.70711, 0.25882, -0.25882, -0.70711, -0.96593]
>>> w
[0.5236, 0.5236, 0.5236, 0.5236, 0.5236, 0.5236]

工具书类

sympy.integrals.quadrature.gauss_chebyshev_u(n, n_digits)[源代码]#

Computes the Gauss-Chebyshev quadrature [R589] points and weights of the second kind.

参数:

n :求积顺序

n_digits :要返回的点和权重的有效位数

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

第二类高斯-切比雪夫积分近似于:

\[\int{-1}^{1}\sqrt{1-x^2}f(x)\,dx\approach\sum{i=1}^n宽i f(x_i)\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(U_n\) 重量呢 \(w_i\) 由以下公式给出:

\[wu i=\frac{\pi}{n+1}\sin^2\左(\frac{i}{n+1}\pi\右)\]

实例

>>> from sympy.integrals.quadrature import gauss_chebyshev_u
>>> x, w = gauss_chebyshev_u(3, 5)
>>> x
[0.70711, 0, -0.70711]
>>> w
[0.3927, 0.7854, 0.3927]
>>> x, w = gauss_chebyshev_u(6, 5)
>>> x
[0.90097, 0.62349, 0.22252, -0.22252, -0.62349, -0.90097]
>>> w
[0.084489, 0.27433, 0.42658, 0.42658, 0.27433, 0.084489]

工具书类

sympy.integrals.quadrature.gauss_jacobi(n, alpha, beta, n_digits)[源代码]#

Computes the Gauss-Jacobi quadrature [R591] points and weights.

参数:

n :求积顺序

阿尔法 :雅可比多项式的第一个参数, \(\alpha > -1\)

beta :雅可比多项式的第二个参数, \(\beta > -1\)

n_digits :要返回的点和权重的有效位数

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

第一类高斯-雅可比积分近似为:

\[\int{-1}^1(1-x)^\alpha(1+x)^\beta f(x)\,dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(P^{{(\alpha,\beta)}}_n\) 重量呢 \(w_i\) 由以下公式给出:

\[wu i=-\frac{2n+\alpha+\beta+2}{n+\alpha+\beta+1}\]

实例

>>> from sympy import S
>>> from sympy.integrals.quadrature import gauss_jacobi
>>> x, w = gauss_jacobi(3, S.Half, -S.Half, 5)
>>> x
[-0.90097, -0.22252, 0.62349]
>>> w
[1.7063, 1.0973, 0.33795]
>>> x, w = gauss_jacobi(6, 1, 1, 5)
>>> x
[-0.87174, -0.5917, -0.2093, 0.2093, 0.5917, 0.87174]
>>> w
[0.050584, 0.22169, 0.39439, 0.39439, 0.22169, 0.050584]

工具书类

sympy.integrals.quadrature.gauss_lobatto(n, n_digits)[源代码]#

Computes the Gauss-Lobatto quadrature [R594] points and weights.

参数:

n :求积顺序

n_digits :要返回的点和权重的有效位数

返回:

(x,w)xw 是浮点数和权重的列表。

要点 \(x_i\) 和重量 \(w_i\) 返回为 (x, w) 列表的元组。

解释

高斯-洛巴托求积近似于积分:

\[\整数{-1}^1f(x),dx\近似值\]

节点 \(x_i\) 命令的 \(n\) 求积法则是 \(P'_(n-1)\) 重量呢 \(w_i\) 由以下公式给出:

\[\begin{split}&w_i = \frac{2}{n(n-1) \left[P_{n-1}(x_i)\right]^2},\quad x\neq\pm 1\\ &w_i = \frac{2}{n(n-1)},\quad x=\pm 1\end{split}\]

实例

>>> from sympy.integrals.quadrature import gauss_lobatto
>>> x, w = gauss_lobatto(3, 5)
>>> x
[-1, 0, 1]
>>> w
[0.33333, 1.3333, 0.33333]
>>> x, w = gauss_lobatto(4, 5)
>>> x
[-1, -0.44721, 0.44721, 1]
>>> w
[0.16667, 0.83333, 0.83333, 0.16667]

工具书类

多面体上的积分#

这个 intpoly SymPy中的模块实现了计算2/3-多面体上多项式积分的方法。使用Chin等人所述的评估技术。(2015年) [1] .

2-多面体或多边形的输入使用已存在的 Polygon SymPy中的数据结构。看到了吗 sympy.geometry.polygon 了解如何创建多边形。

对于3-多面体或多面体,最经济的表示方法是指定顶点列表,然后将每个构成面(多边形)作为顶点索引列表提供。

例如,考虑单位立方体。下面是它的表现方式。

unit_cube = [[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0),(1, 0, 1), (1, 1, 0), (1, 1, 1)],

[3, 7, 6, 2], [1, 5, 7, 3], [5, 4, 6, 7], [0, 4, 5, 1], [2, 0, 1, 3], [2, 6, 4, 0]]

这里,第一个子列表是顶点列表。其他较小的列表如 [3, 7, 6, 2] 表示具有索引顶点的多面体的二维面 3, 7, 6 and 2 在第一个子列表中(按该顺序)。

本模块的主要方法是 polytope_integrate()

  • polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), x) 返回的积分 \(x\) 在顶点(0、0)、(0、1)和(1、0)的三角形上

  • polytope_integrate(unit_cube, x + y + z) 返回的积分 \(x + y + z\) 在单位立方体上。

工具书类#

[1] :Chin、Eric B、Jean B.Lasserre和N.Sukumar。”凸和非凸多边形和多面体上齐次函数的数值积分〉,《计算力学》56.6(2015):967-981

PDF链接:http://dilbert.engr.ucdavis.edu/~suku/quarequare/cls-integration.pdf

实例#

对于二维多边形#

单多项式:

>>> from sympy.integrals.intpoly import *
>>> init_printing(use_unicode=False, wrap_line=False)
>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), x)
1/6
>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), x + x*y + y**2)
7/24

指定多项式列表:

>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), [3, x*y + y**2, x**4], max_degree=4)
          4               2
{3: 3/2, x : 1/30, x*y + y : 1/8}
>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), [1.125, x, x**2, 6.89*x**3, x*y + y**2, x**4], max_degree=4)
                       2              3  689    4               2
{1.125: 9/16, x: 1/6, x : 1/12, 6.89*x : ----, x : 1/30, x*y + y : 1/8}
                                         2000

最大程度地计算所有单项式:

>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)),max_degree=3)
                        2         3                 2         3                      2         2
{0: 0, 1: 1/2, x: 1/6, x : 1/12, x : 1/20, y: 1/6, y : 1/12, y : 1/20, x*y: 1/24, x*y : 1/60, x *y: 1/60}

对于3多面体/多面体#

单多项式:

>>> from sympy.integrals.intpoly import *
>>> cube = [[(0, 0, 0), (0, 0, 5), (0, 5, 0), (0, 5, 5), (5, 0, 0), (5, 0, 5), (5, 5, 0), (5, 5, 5)], [2, 6, 7, 3], [3, 7, 5, 1], [7, 6, 4, 5], [1, 5, 4, 0], [3, 1, 0, 2], [0, 4, 6, 2]]
>>> polytope_integrate(cube, x**2 + y**2 + z**2 + x*y + y*z + x*z)
-21875/4
>>> octahedron = [[(S(-1) / sqrt(2), 0, 0), (0, S(1) / sqrt(2), 0), (0, 0, S(-1) / sqrt(2)), (0, 0, S(1) / sqrt(2)), (0, S(-1) / sqrt(2), 0), (S(1) / sqrt(2), 0, 0)], [3, 4, 5], [3, 5, 1], [3, 1, 0], [3, 0, 4], [4, 0, 2], [4, 2, 5], [2, 0, 1], [5, 2, 1]]
>>> polytope_integrate(octahedron, x**2 + y**2 + z**2 + x*y + y*z + x*z)
  ___
\/ 2
-----
  20

指定多项式列表:

>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), [3, x*y + y**2, x**4], max_degree=4)
          4               2
{3: 3/2, x : 1/30, x*y + y : 1/8}
>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)), [1.125, x, x**2, 6.89*x**3, x*y + y**2, x**4], max_degree=4)
                       2              3  689    4               2
{1.125: 9/16, x: 1/6, x : 1/12, 6.89*x : ----, x : 1/30, x*y + y : 1/8}
                                         2000

最大程度地计算所有单项式:

>>> polytope_integrate(Polygon((0, 0), (0, 1), (1, 0)),max_degree=3)
                        2         3                 2         3                      2         2
{0: 0, 1: 1/2, x: 1/6, x : 1/12, x : 1/20, y: 1/6, y : 1/12, y : 1/20, x*y: 1/24, x*y : 1/60, x *y: 1/60}

API引用#

sympy.integrals.intpoly.polytope_integrate(poly, expr=None, *, clockwise=False, max_degree=None)[源代码]#

在2/3-多面体上积分多项式。

参数:

poly :输入多边形。

expr :输入多项式。

顺时针方向的 :二进制值,顺时针排序2-多面体的输入点。(可选)

max_degree :输入多项式任何单项式的最大次数。(可选)

解释

This function accepts the polytope in poly and the function in expr (uni/bi/trivariate polynomials are implemented) and returns the exact integral of expr over poly.

实例

>>> from sympy.abc import x, y
>>> from sympy import Point, Polygon
>>> from sympy.integrals.intpoly import polytope_integrate
>>> polygon = Polygon(Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 0))
>>> polys = [1, x, y, x*y, x**2*y, x*y**2]
>>> expr = x*y
>>> polytope_integrate(polygon, expr)
1/4
>>> polytope_integrate(polygon, polys, max_degree=3)
{1: 1, x: 1/2, y: 1/2, x*y: 1/4, x*y**2: 1/6, x**2*y: 1/6}