假设我有
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
。折衷方案是仅评估简单积分(在微积分课程的水平上)。就是说,我不能100%地确定
manualintegrate
模块中的所有集成规则在编写时都可能会缺乏可交换性。