有谁知道 sympy 中是否有内置函数来获得形式的多元级数展开
f(x,y) = a + b*x + c*y + d*x**2 + e*x*y + f*y**2 + ...
即所有变量的升序?
提前致谢。
这可能为时已晚,但这是我会做的。它不完全是一个内置函数,但它可以完成这项工作。这个想法是使用替换引入一个临时变量 (eps) 并在其上扩展系列。这是一个例子:
import sympy
x, y , eps = sympy.symbols('x y eps')
f = sympy.exp(x-y)
f.subs(x,x*eps).subs(y,y*eps).series(eps).removeO().subs(eps,1)
请注意,使用这种技术,您可以在 x 和 y 中进行“不对称”扩展。例如:
f.subs(x,x*eps).subs(y,y*eps**2)
...
简短的回答是目前(sympy build 0.7.5),sympy 中没有内置函数可以处理多变量级数展开。
似乎只支持一个变量中的多变量函数的级数展开。您可以在此处_eval_nseries
的文档中的function
文档字符串中看到这一点。如果这对您很重要,您可以在问题跟踪器上发表评论或加入邮件列表。
所以,要清楚,这有效:
In [1]: import sympy as sp
In [2]: x, y = sp.symbols('x,y')
In [3]: g = sp.exp(-x*y)
In [4]: g
Out[4]: exp(-x*y)
In [5]: g.series(x, 0)
Out[5]: 1 - x*y + x**2*y**2/2 - x**3*y**3/6 + x**4*y**4/24 - x**5*y**5/120 + O(x**6)
In [6]: g.series(y, 0)
Out[6]: 1 - x*y + x**2*y**2/2 - x**3*y**3/6 + x**4*y**4/24 - x**5*y**5/120 + O(y**6)
但以下任何一项都没有您想要的功能:
In [7]: g.series((x, y), (0, 0))
Out[7]: exp(-x*y)
In [8]: g.series((x, 0), (y, 0))
Out[8]: exp(-x*y)
In [9]: g.series(x, 0, y, 0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-20c1ab732928> in <module>()
----> 1 g.series(x, 0, y, 0)
/usr/lib/python2.7/dist-packages/sympy/core/expr.pyc in series(self, x, x0, n, dir, logx)
2401 return self
2402
-> 2403 if len(dir) != 1 or dir not in '+-':
2404 raise ValueError("Dir must be '+' or '-'")
2405
TypeError: object of type 'int' has no len()
In [10]: g.series(x, y, 0, 0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-32b57736cd3d> in <module>()
----> 1 g.series(x, y, 0, 0)
/usr/lib/python2.7/dist-packages/sympy/core/expr.pyc in series(self, x, x0, n, dir, logx)
2401 return self
2402
-> 2403 if len(dir) != 1 or dir not in '+-':
2404 raise ValueError("Dir must be '+' or '-'")
2405
TypeError: object of type 'int' has no len()