gpt4 book ai didi

python - 与 Sympy 中的非交换符号集成

转载 作者:太空宇宙 更新时间:2023-11-04 04:48:16 25 4
gpt4 key购买 nike

假设我有

x=Symbol('x',commutative=False)

还有一些表情

expr = x**2+x

那么如果你尝试整合这个

integrate(expr,x)

出现以下错误:

  Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 1295, in integrate
risch=risch, manual=manual)
File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 486, in doit
conds=conds)
File "/usr/local/lib/python2.7/dist-packages/sympy/integrals/integrals.py", line 774, in _eval_integral
poly = f.as_poly(x)
File "/usr/local/lib/python2.7/dist-packages/sympy/core/basic.py", line 706, in as_poly
poly = Poly(self, *gens, **args)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/polytools.py", line 113, in __new__
opt = options.build_options(gens, args)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/polyoptions.py", line 731, in build_options
return Options(gens, args)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/polyoptions.py", line 154, in __init__
preprocess_options(args)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/polyoptions.py", line 152, in preprocess_options
self[option] = cls.preprocess(value)
File "/usr/local/lib/python2.7/dist-packages/sympy/polys/polyoptions.py", line 293, in preprocess
raise GeneratorsError("non-commutative generators: %s" % str(gens))
sympy.polys.polyerrors.GeneratorsError: non-commutative generators: (x,)

有什么办法可以解决这个问题吗?因为我真的需要 x 是不可交换的

最佳答案

事实上,高级积分方法(Risch、Meijer G)需要变量是可交换的;他们依靠多项式像往常一样工作。将积分方法限制为“手动”(初等微积分技术)可避免错误:

x = Symbol('x',commutative=False)
integrate(x**2 + x, x, manual=True)

返回 x**2/2 + x**3/3。权衡是只评估简单的积分(在微积分类(class)的水平上)。

也就是说,我不能 100% 确定 manualintegrate 模块中的所有积分规则都是在考虑到可能缺乏交换性的情况下编写的。

关于python - 与 Sympy 中的非交换符号集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48999613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com