Given a series in variables x, y, z, I want to extract the kth term of this series using Sympy.
Say the series is given by exp(y) and k=2, I’d like the output to be 1/2.
The following works fine
from sympy import symbols, series, exp
x, y, z = symbols('x y z')
expr = exp(y)
k=2
series = series(expr, y, n=10)
kth_coeff = series.coeff(y, k)
print(kth_coeff)
But
from sympy import symbols, series, exp
x, y, z = symbols('x y z')
expr = -exp(3*x/(z*y))*exp(z*y/x + 1/x)
k=2
series = series(expr, y, n=10)
kth_coeff = series.coeff(y, k)
print(kth_coeff)
returns -z**2*exp(3*x/(z*y) + 1/x)/(2*x**2)
, which clearly is not the second coefficient.