微积分#
微积分相关方法。
这个模块实现了一种为给定的拉格朗日方程寻找欧拉-拉格朗日方程的方法。
- sympy.calculus.euler.euler_equations(L, funcs=(), vars=())[源代码]#
Find the Euler-Lagrange equations [R31] for a given Lagrangian.
- 参数:
L :表达式
拉格朗日函数,它应该是第二个参数中列出的函数及其导数的函数。
For example, in the case of two functions \(f(x,y)\), \(g(x,y)\) and two independent variables \(x\), \(y\) the Lagrangian has the form:
\[左(f(x,y),g(x,y),\frac{\partial f(x,y)}{\partial x},\]In many cases it is not necessary to provide anything, except the Lagrangian, it will be auto-detected (and an error raised if this cannot be done).
函数 :函数或函数的iterable
拉格朗日所依赖的函数。欧拉方程是这些函数的微分方程。
vars :符号或一系列符号
作为函数自变量的符号。
- 返回:
eqns :Eq列表
微分方程的列表,每个函数对应一个。
实例
>>> from sympy import euler_equations, Symbol, Function >>> x = Function('x') >>> t = Symbol('t') >>> L = (x(t).diff(t))**2/2 - x(t)**2/2 >>> euler_equations(L, x(t), t) [Eq(-x(t) - Derivative(x(t), (t, 2)), 0)] >>> u = Function('u') >>> x = Symbol('x') >>> L = (u(t, x).diff(t))**2/2 - (u(t, x).diff(x))**2/2 >>> euler_equations(L, u(t, x), [t, x]) [Eq(-Derivative(u(t, x), (t, 2)) + Derivative(u(t, x), (x, 2)), 0)]
工具书类
奇点#
该模块实现了寻找函数奇点和识别函数类型的算法。
本模块中的微积分方法包括识别给定函数类型的方法 Interval
:-递增-严格递增-递减-严格递减-单调
- sympy.calculus.singularities.is_decreasing(expression, interval=Reals, symbol=None)[源代码]#
返回函数是否在给定间隔内递减。
- 参数:
表达 :表达式
正在检查的目标函数。
间隔 :设置,可选
我们正在测试的值的范围(默认为所有实数的集合)。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
- 返回:
布尔
如果真
expression
在给定的interval
,否则为False。
实例
>>> from sympy import is_decreasing >>> from sympy.abc import x, y >>> from sympy import S, Interval, oo >>> is_decreasing(1/(x**2 - 3*x), Interval.open(S(3)/2, 3)) True >>> is_decreasing(1/(x**2 - 3*x), Interval.open(1.5, 3)) True >>> is_decreasing(1/(x**2 - 3*x), Interval.Lopen(3, oo)) True >>> is_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, S(3)/2)) False >>> is_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, 1.5)) False >>> is_decreasing(-x**2, Interval(-oo, 0)) False >>> is_decreasing(-x**2 + y, Interval(-oo, 0), x) False
- sympy.calculus.singularities.is_increasing(expression, interval=Reals, symbol=None)[源代码]#
返回函数是否在给定间隔内递增。
- 参数:
表达 :表达式
正在检查的目标函数。
间隔 :设置,可选
我们正在测试的值的范围(默认为所有实数的集合)。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
- 返回:
布尔
如果真
expression
在给定的interval
,否则为False。
实例
>>> from sympy import is_increasing >>> from sympy.abc import x, y >>> from sympy import S, Interval, oo >>> is_increasing(x**3 - 3*x**2 + 4*x, S.Reals) True >>> is_increasing(-x**2, Interval(-oo, 0)) True >>> is_increasing(-x**2, Interval(0, oo)) False >>> is_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval(-2, 3)) False >>> is_increasing(x**2 + y, Interval(1, 2), x) True
- sympy.calculus.singularities.is_monotonic(expression, interval=Reals, symbol=None)[源代码]#
返回函数在给定间隔内是否单调。
- 参数:
表达 :表达式
正在检查的目标函数。
间隔 :设置,可选
我们正在测试的值的范围(默认为所有实数的集合)。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
- 返回:
布尔
如果真
expression
在给定的条件下是单调的interval
,否则为False。- 加薪:
NotImplementedError
尚未对查询的函数执行单调性检查。
实例
>>> from sympy import is_monotonic >>> from sympy.abc import x, y >>> from sympy import S, Interval, oo >>> is_monotonic(1/(x**2 - 3*x), Interval.open(S(3)/2, 3)) True >>> is_monotonic(1/(x**2 - 3*x), Interval.open(1.5, 3)) True >>> is_monotonic(1/(x**2 - 3*x), Interval.Lopen(3, oo)) True >>> is_monotonic(x**3 - 3*x**2 + 4*x, S.Reals) True >>> is_monotonic(-x**2, S.Reals) False >>> is_monotonic(x**2 + y + 1, Interval(1, 2), x) True
- sympy.calculus.singularities.is_strictly_decreasing(expression, interval=Reals, symbol=None)[源代码]#
返回函数是否在给定间隔内严格递减。
- 参数:
表达 :表达式
正在检查的目标函数。
间隔 :设置,可选
我们正在测试的值的范围(默认为所有实数的集合)。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
- 返回:
布尔
如果真
expression
在给定的interval
,否则为False。
实例
>>> from sympy import is_strictly_decreasing >>> from sympy.abc import x, y >>> from sympy import S, Interval, oo >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Lopen(3, oo)) True >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, S(3)/2)) False >>> is_strictly_decreasing(1/(x**2 - 3*x), Interval.Ropen(-oo, 1.5)) False >>> is_strictly_decreasing(-x**2, Interval(-oo, 0)) False >>> is_strictly_decreasing(-x**2 + y, Interval(-oo, 0), x) False
- sympy.calculus.singularities.is_strictly_increasing(expression, interval=Reals, symbol=None)[源代码]#
返回函数是否在给定间隔内严格递增。
- 参数:
表达 :表达式
正在检查的目标函数。
间隔 :设置,可选
我们正在测试的值的范围(默认为所有实数的集合)。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
- 返回:
布尔
如果真
expression
在给定的interval
,否则为False。
实例
>>> from sympy import is_strictly_increasing >>> from sympy.abc import x, y >>> from sympy import Interval, oo >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Ropen(-oo, -2)) True >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.Lopen(3, oo)) True >>> is_strictly_increasing(4*x**3 - 6*x**2 - 72*x + 30, Interval.open(-2, 3)) False >>> is_strictly_increasing(-x**2, Interval(0, oo)) False >>> is_strictly_increasing(-x**2 + y, Interval(-oo, 0), x) False
- sympy.calculus.singularities.monotonicity_helper(expression, predicate, interval=Reals, symbol=None)[源代码]#
函数检查函数单调性的辅助函数。
- 参数:
表达 :表达式
正在检查的目标函数
谓语 :函数
正在测试的属性。函数接受一个整数并返回一个布尔值。整数输入是导数,如果属性被保留,布尔结果应该为true,否则为false。
间隔 :设置,可选
我们测试的值范围默认为所有实数。
符号 :符号,可选
表达式中出现的符号,在给定范围内变化。
它返回一个布尔值,指示
满足给定谓词的函数导数是超集
在给定的时间间隔内。
- 返回:
布尔
如果真
predicate
当symbol
是多种多样的range
,否则为False。
- sympy.calculus.singularities.singularities(expression, symbol, domain=None)[源代码]#
求给定函数的奇点。
- 参数:
表达 :表达式
需要找到奇异点的目标函数。
符号 :符号
在其值上的符号,其表达式中的奇点正在被搜索。
- 返回:
集合
的一组值
symbol
为此expression
有一个奇点。安EmptySet
如果返回expression
的任何给定值都没有奇点Symbol
.- 加薪:
NotImplementedError
确定这个函数奇异性的方法还没有发展出来。
笔记
这个函数既不能找到非孤立的奇点,也不能找到表达式的分支点。
- 当前支持的功能有:
一元连续(实或复)函数
实例
>>> from sympy import singularities, Symbol, log >>> x = Symbol('x', real=True) >>> y = Symbol('y', real=False) >>> singularities(x**2 + x + 1, x) EmptySet >>> singularities(1/(x + 1), x) {-1} >>> singularities(1/(y**2 + 1), y) {-I, I} >>> singularities(1/(y**3 + 1), y) {-1, 1/2 - sqrt(3)*I/2, 1/2 + sqrt(3)*I/2} >>> singularities(log(x), x) {0}
工具书类
有限差分权#
该模块实现了一种有效生成函数从0(插值)到任意阶导数的常微分的有限差分权重的算法。
在有限差分权函数中给出了核心算法 (finite_diff_weights
),提供两个方便功能:
- 直接从一系列点估计导数(或插值)
也提供了 (
apply_finite_diff
)
- 用有限差分近似求微分
(
differentiate_finite
)
- sympy.calculus.finite_diff.apply_finite_diff(order, x_list, y_list, x0=0)[源代码]#
计算请求阶导数的有限差分近似
x0
从中提供的点x_list
和y_list
.- 参数:
顺序:int
导数到近似的阶数。0对应于插值。
x_list: sequence
自变量的(唯一)值序列。
y_list: sequence
在xu列表中自变量对应值处的函数值。
x0:数字或符号
在自变量的什么值时,导数应该被计算。默认为0。
- 返回:
sympy.core.add.添加或sympy.core.numbers公司.编号
近似于要求导数阶数的有限差分表达式
x0
.
实例
>>> from sympy import apply_finite_diff >>> cube = lambda arg: (1.0*arg)**3 >>> xlist = range(-3,3+1) >>> apply_finite_diff(2, xlist, map(cube, xlist), 2) - 12 -3.55271367880050e-15
我们看到上面的例子只包含舍入错误。apply_finite_diff也可以用于更抽象的对象:
>>> from sympy import IndexedBase, Idx >>> x, y = map(IndexedBase, 'xy') >>> i = Idx('i') >>> x_list, y_list = zip(*[(x[i+j], y[i+j]) for j in range(-1,2)]) >>> apply_finite_diff(1, x_list, y_list, x[i]) ((x[i + 1] - x[i])/(-x[i - 1] + x[i]) - 1)*y[i]/(x[i + 1] - x[i]) - (x[i + 1] - x[i])*y[i - 1]/((x[i + 1] - x[i - 1])*(-x[i - 1] + x[i])) + (-x[i - 1] + x[i])*y[i + 1]/((x[i + 1] - x[i - 1])*(x[i + 1] - x[i]))
笔记
Order=0对应于插值。在提取导数时,只提供您认为对x0有意义的点(函数需要在该区域内表现良好)。还要注意伦格现象。
工具书类
Fortran 90实现,使用Python接口实现数字: finitediff
- sympy.calculus.finite_diff.differentiate_finite(expr, *symbols, points=1, x0=None, wrt=None, evaluate=False)[源代码]#
微分表达式并用有限差分代替导数。
- 参数:
expr :表达式
*symbols :区分符号
点:序列、系数或未定义函数,可选
看见
Derivative.as_finite_difference
x0:数字或符号,可选
看见
Derivative.as_finite_difference
wrt:符号,可选
看见
Derivative.as_finite_difference
实例
>>> from sympy import sin, Function, differentiate_finite >>> from sympy.abc import x, y, h >>> f, g = Function('f'), Function('g') >>> differentiate_finite(f(x)*g(x), x, points=[x-h, x+h]) -f(-h + x)*g(-h + x)/(2*h) + f(h + x)*g(h + x)/(2*h)
differentiate_finite
处理任何表达式,包括包含嵌入导数的表达式:>>> differentiate_finite(f(x) + sin(x), x, 2) -2*f(x) + f(x - 1) + f(x + 1) - 2*sin(x) + sin(x - 1) + sin(x + 1) >>> differentiate_finite(f(x, y), x, y) f(x - 1/2, y - 1/2) - f(x - 1/2, y + 1/2) - f(x + 1/2, y - 1/2) + f(x + 1/2, y + 1/2) >>> differentiate_finite(f(x)*g(x).diff(x), x) (-g(x) + g(x + 1))*f(x + 1/2) - (g(x) - g(x - 1))*f(x - 1/2)
要使用非恒定离散化步骤进行有限差分,请使用未定义的函数:
>>> dx = Function('dx') >>> differentiate_finite(f(x)*g(x).diff(x), points=dx(x)) -(-g(x - dx(x)/2 - dx(x - dx(x)/2)/2)/dx(x - dx(x)/2) + g(x - dx(x)/2 + dx(x - dx(x)/2)/2)/dx(x - dx(x)/2))*f(x - dx(x)/2)/dx(x) + (-g(x + dx(x)/2 - dx(x + dx(x)/2)/2)/dx(x + dx(x)/2) + g(x + dx(x)/2 + dx(x + dx(x)/2)/2)/dx(x + dx(x)/2))*f(x + dx(x)/2)/dx(x)
- sympy.calculus.finite_diff.finite_diff_weights(order, x_list, x0=1)[源代码]#
计算任意间距一维网格的有限差分权重 (
x_list
)对于衍生品x0
0,1,…,直到order
使用递归公式。准确的顺序至少是len(x_list) - order
如果x_list
定义正确。- 参数:
顺序:int
应计算到什么样的导数阶权重。0对应于插值。
x_list: sequence
自变量的(唯一)值序列。订购是有用的(但不是必要的)
x_list
从最近到最远x0
;参见下面的示例。x0:数字或符号
应为其生成有限差分权重的自变量的根或值。默认为
S.One
.- 返回:
列表
子列表的一种列表,每个子列表对应于增加导数阶数的系数,每个子列表包含用于增加x_列表子集的系数列表。
实例
>>> from sympy import finite_diff_weights, S >>> res = finite_diff_weights(1, [-S(1)/2, S(1)/2, S(3)/2, S(5)/2], 0) >>> res [[[1, 0, 0, 0], [1/2, 1/2, 0, 0], [3/8, 3/4, -1/8, 0], [5/16, 15/16, -5/16, 1/16]], [[0, 0, 0, 0], [-1, 1, 0, 0], [-1, 1, 0, 0], [-23/24, 7/8, 1/8, -1/24]]] >>> res[0][-1] # FD weights for 0th derivative, using full x_list [5/16, 15/16, -5/16, 1/16] >>> res[1][-1] # FD weights for 1st derivative [-23/24, 7/8, 1/8, -1/24] >>> res[1][-2] # FD weights for 1st derivative, using x_list[:-1] [-1, 1, 0, 0] >>> res[1][-1][0] # FD weight for 1st deriv. for x_list[0] -23/24 >>> res[1][-1][1] # FD weight for 1st deriv. for x_list[1], etc. 7/8
每个子列表的末尾都包含最精确的公式。注意,在上面的例子中
res[1][1]
是一样的res[1][2]
. 自res [1] [2] 精确到len(x_list[:3]) - order = 3 - 1 = 2
,对于res[1][1]
你说什么?>>> res = finite_diff_weights(1, [S(0), S(1), -S(1), S(2), -S(2)], 0)[1] >>> res [[0, 0, 0, 0, 0], [-1, 1, 0, 0, 0], [0, 1/2, -1/2, 0, 0], [-1/2, 1, -1/3, -1/6, 0], [0, 2/3, -2/3, -1/12, 1/12]] >>> res[0] # no approximation possible, using x_list[0] only [0, 0, 0, 0, 0] >>> res[1] # classic forward step approximation [-1, 1, 0, 0, 0] >>> res[2] # classic centered approximation [0, 1/2, -1/2, 0, 0] >>> res[3:] # higher order approximations [[-1/2, 1, -1/3, -1/6, 0], [0, 2/3, -2/3, -1/12, 1/12]]
让我们将其与另一个定义不同的
x_list
. 注意foo[i][k]
与定义的网格点相对应x_list[k]
.>>> foo = finite_diff_weights(1, [-S(2), -S(1), S(0), S(1), S(2)], 0)[1] >>> foo [[0, 0, 0, 0, 0], [-1, 1, 0, 0, 0], [1/2, -2, 3/2, 0, 0], [1/6, -1, 1/2, 1/3, 0], [1/12, -2/3, 0, 2/3, -1/12]] >>> foo[1] # not the same and of lower accuracy as res[1]! [-1, 1, 0, 0, 0] >>> foo[2] # classic double backward step approximation [1/2, -2, 3/2, 0, 0] >>> foo[4] # the same as res[4] [1/12, -2/3, 0, 2/3, -1/12]
请注意,除非您计划使用基于
x_list
,网格点的顺序无关紧要。可以使用在任意点生成权重的能力,例如通过使用切比雪夫节点来最小化Runge现象:
>>> from sympy import cos, symbols, pi, simplify >>> N, (h, x) = 4, symbols('h x') >>> x_list = [x+h*cos(i*pi/(N)) for i in range(N,-1,-1)] # chebyshev nodes >>> print(x_list) [-h + x, -sqrt(2)*h/2 + x, x, sqrt(2)*h/2 + x, h + x] >>> mycoeffs = finite_diff_weights(1, x_list, 0)[1][4] >>> [simplify(c) for c in mycoeffs] [(h**3/2 + h**2*x - 3*h*x**2 - 4*x**3)/h**4, (-sqrt(2)*h**3 - 4*h**2*x + 3*sqrt(2)*h*x**2 + 8*x**3)/h**4, (6*h**2*x - 8*x**3)/h**4, (sqrt(2)*h**3 - 4*h**2*x - 3*sqrt(2)*h*x**2 + 8*x**3)/h**4, (-h**3/2 + h**2*x + 3*h*x**2 - 4*x**3)/h**4]
笔记
如果需要三阶导数的有限差分近似的权重,则0阶、1阶和2阶的权重将“免费”计算,使用
x_list
. 这是一个可以利用的东西来节省计算成本。要知道你应该定义x_list
从最近到最远x0
. 如果不是,则为x_list
会产生更差的近似值,可能不会达到len(x_list) - order
.工具书类
[R33]任意间距网格上有限差分公式的生成;计算数学;51;184;(1988);699-706;doi:10.1090/S0025-5718-1988-0935077-0
- sympy.calculus.util.continuous_domain(f, symbol, domain)[源代码]#
Returns the domain on which the function expression f is continuous.
This function is limited by the ability to determine the various singularities and discontinuities of the given function. The result is either given as a union of intervals or constructed using other set operations.
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
要确定其间隔的变量。
domain :
Interval
必须检查符号连续性的域。
- 返回:
-
函数连续的所有区间的并。
- 加薪:
NotImplementedError
如果确定这种函数连续性的方法还没有发展出来。
实例
>>> from sympy import Interval, Symbol, S, tan, log, pi, sqrt >>> from sympy.calculus.util import continuous_domain >>> x = Symbol('x') >>> continuous_domain(1/x, x, S.Reals) Union(Interval.open(-oo, 0), Interval.open(0, oo)) >>> continuous_domain(tan(x), x, Interval(0, pi)) Union(Interval.Ropen(0, pi/2), Interval.Lopen(pi/2, pi)) >>> continuous_domain(sqrt(x - 2), x, Interval(-5, 5)) Interval(2, 5) >>> continuous_domain(log(2*x - 1), x, S.Reals) Interval.open(1/2, oo)
- sympy.calculus.util.function_range(f, symbol, domain)[源代码]#
在给定域中查找函数的范围。这种方法受到确定奇异点和确定极限的能力的限制。
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
要确定其函数范围的变量。
domain :
Interval
必须在其中找到函数范围的域。
- 返回:
-
函数连续域下所有区间的所有区间的并集。
- 加薪:
NotImplementedError
If any of the intervals, in the given domain, for which function is continuous are not finite or real, OR if the critical points of the function on the domain cannot be found.
实例
>>> from sympy import Interval, Symbol, S, exp, log, pi, sqrt, sin, tan >>> from sympy.calculus.util import function_range >>> x = Symbol('x') >>> function_range(sin(x), x, Interval(0, 2*pi)) Interval(-1, 1) >>> function_range(tan(x), x, Interval(-pi/2, pi/2)) Interval(-oo, oo) >>> function_range(1/x, x, S.Reals) Union(Interval.open(-oo, 0), Interval.open(0, oo)) >>> function_range(exp(x), x, S.Reals) Interval.open(0, oo) >>> function_range(log(x), x, S.Reals) Interval(-oo, oo) >>> function_range(sqrt(x), x, Interval(-5, 9)) Interval(0, 3)
- sympy.calculus.util.is_convex(f, *syms, domain=Reals)[源代码]#
确定参数中传递的函数的凸性。
- 参数:
f :
Expr
相关功能。
syms : Tuple of
Symbol
确定凸度的变量。
domain :
Interval
, optional必须检查函数凸性的域。如果未指定,S.Reals将是默认域。
- 返回:
bool
The method returns
True
if the function is convex otherwise it returnsFalse
.- 加薪:
NotImplementedError
多元函数的凸性检验尚未实现。
笔记
To determine concavity of a function pass \(-f\) as the concerned function. To determine logarithmic convexity of a function pass \(\log(f)\) as concerned function. To determine logarithmic concavity of a function pass \(-\log(f)\) as concerned function.
目前,没有处理多元函数的凸性检验。
实例
>>> from sympy import is_convex, symbols, exp, oo, Interval >>> x = symbols('x') >>> is_convex(exp(x), x) True >>> is_convex(x**3, x, domain = Interval(-1, oo)) False >>> is_convex(1/x**2, x, domain=Interval.open(0, oo)) True
工具书类
- sympy.calculus.util.lcim(numbers)[源代码]#
返回一组数字的最小公倍数。
这些数字可以是有理数,也可以是无理数,或者两者兼而有之。 \(None\) 对于不可通约的数字返回。
- 参数:
数字 :列表
找到lcim的数字(有理和/或无理性)。
- 返回:
数
lcim if it exists, otherwise
None
for incommensurable numbers.
实例
>>> from sympy.calculus.util import lcim >>> from sympy import S, pi >>> lcim([S(1)/2, S(3)/4, S(5)/6]) 15/2 >>> lcim([2*pi, 3*pi, pi, pi/2]) 6*pi >>> lcim([S(1), 2*pi])
- sympy.calculus.util.maximum(f, symbol, domain=Reals)[源代码]#
返回给定域中函数的最大值。
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
需要确定最大值的变量。
domain :
Interval
The domain over which the maximum have to be checked. If unspecified, then the global maximum is returned.
- 返回:
数
给定域中函数的最大值。
实例
>>> from sympy import Interval, Symbol, S, sin, cos, pi, maximum >>> x = Symbol('x')
>>> f = -x**2 + 2*x + 5 >>> maximum(f, x, S.Reals) 6
>>> maximum(sin(x), x, Interval(-pi, pi/4)) sqrt(2)/2
>>> maximum(sin(x)*cos(x), x) 1/2
- sympy.calculus.util.minimum(f, symbol, domain=Reals)[源代码]#
返回给定域中函数的最小值。
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
需要确定最小值的变量。
domain :
Interval
The domain over which the minimum have to be checked. If unspecified, then the global minimum is returned.
- 返回:
数
给定域中函数的最小值。
实例
>>> from sympy import Interval, Symbol, S, sin, cos, minimum >>> x = Symbol('x')
>>> f = x**2 + 2*x + 5 >>> minimum(f, x, S.Reals) 4
>>> minimum(sin(x), x, Interval(2, 3)) sin(3)
>>> minimum(sin(x)*cos(x), x) -1/2
- sympy.calculus.util.not_empty_in(finset_intersection, *syms)[源代码]#
Finds the domain of the functions in
finset_intersection
in which thefinite_set
is not-empty.- 参数:
finset_intersection : Intersection of FiniteSet
The unevaluated intersection of FiniteSet containing real-valued functions with Union of Sets
syms :符号元组
要找到的域的符号
- 加薪:
NotImplementedError
寻找给定有限集的非空性的算法尚未实现。
ValueError
输入无效。
RuntimeError
这是一个bug,请向github问题跟踪程序报告(https://github.com/sympy/sympy/issues).
实例
>>> from sympy import FiniteSet, Interval, not_empty_in, oo >>> from sympy.abc import x >>> not_empty_in(FiniteSet(x/2).intersect(Interval(0, 1)), x) Interval(0, 2) >>> not_empty_in(FiniteSet(x, x**2).intersect(Interval(1, 2)), x) Union(Interval(1, 2), Interval(-sqrt(2), -1)) >>> not_empty_in(FiniteSet(x**2/(x + 2)).intersect(Interval(1, oo)), x) Union(Interval.Lopen(-2, -1), Interval(2, oo))
- sympy.calculus.util.periodicity(f, symbol, check=False)[源代码]#
测试给定函数在给定符号中的周期性。
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
要确定其周期的变量。
check : bool, optional
用于验证返回的值是否为句点的标志。
- 返回:
时期
The period of the function is returned.
None
is returned when the function is aperiodic or has a complex period. The value of \(0\) is returned as the period of a constant function.- 加薪:
NotImplementedError
无法验证计算的期间值。
笔记
Currently, we do not support functions with a complex period. The period of functions having complex periodic values such as
exp
,sinh
is evaluated toNone
.返回的值可能不是给定函数的“基本”周期,也就是说,它可能不是函数的最小周期值。
The verification of the period through the
check
flag is not reliable due to internal simplification of the given expression. Hence, it is set toFalse
by default.实例
>>> from sympy import periodicity, Symbol, sin, cos, tan, exp >>> x = Symbol('x') >>> f = sin(x) + sin(2*x) + sin(3*x) >>> periodicity(f, x) 2*pi >>> periodicity(sin(x)*cos(x), x) pi >>> periodicity(exp(tan(2*x) - 1), x) pi/2 >>> periodicity(sin(4*x)**cos(2*x), x) pi >>> periodicity(exp(x), x)
- sympy.calculus.util.stationary_points(f, symbol, domain=Reals)[源代码]#
返回给定域中函数的平稳点(其中函数的导数为0)。
- 参数:
f :
Expr
相关功能。
symbol :
Symbol
要确定其静止点的变量。
domain :
Interval
The domain over which the stationary points have to be checked. If unspecified,
S.Reals
will be the default domain.- 返回:
集合
A set of stationary points for the function. If there are no stationary point, an
EmptySet
is returned.
实例
>>> from sympy import Interval, Symbol, S, sin, pi, pprint, stationary_points >>> x = Symbol('x')
>>> stationary_points(1/x, x, S.Reals) EmptySet
>>> pprint(stationary_points(sin(x), x), use_unicode=False) pi 3*pi {2*n*pi + -- | n in Integers} U {2*n*pi + ---- | n in Integers} 2 2
>>> stationary_points(sin(x),x, Interval(0, 4*pi)) {pi/2, 3*pi/2, 5*pi/2, 7*pi/2}