Expansión de series multivariadas en sympy
Frecuentes
Visto 2,003 veces
2 Respuestas
6
It is maybe too late but here is what I would do. It is not exactly a builtin function but it does the job. The idea is to introduce a temporary variable (eps) using substitutions and to expand the series over it. Here is an example:
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)
Note that using this technique you can have "asymmetric" expansions in x and y.
For instance:
f.subs(x,x*eps).subs(y,y*eps**2)
...
Respondido el 04 de diciembre de 14 a las 13:12
2
The short answer is that currently (sympy build 0.7.5), there is no built-in function in sympy that will handle multivariate series expansions.
There appears to be support for series expansion of multivariate functions in . solo variables. You can see this in the docstring of _eval_nseries
en el capítulo respecto a la function
documentación aquí. If this is important to you, you can comment on the Rastreador de problemas o unirse a la lista de correo.
So, to be clear, this works:
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)
but there is none of your desired functionality in any of the following:
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()
contestado el 12 de mayo de 14 a las 23:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas python sympy or haz tu propia pregunta.
What do you start with (a polynomial, some other (analytic) function)? What kind of output do you expect? (A polynomial, a list of monomials, something different?) - Piotr Migdal
Hi Piotr, I am interested in power series expansions of any multivariate function, as a multivariate variant of "series": - doetoe
I had meant to continue with an example: something like (exp(x)*exp(y)).series() giving 1 + x + y + x2/2 + x*y + y2/2 + ... - doetoe