You can use the coeff () method to extract the coefficients of a polynomial, but when it comes to fractional formulas, you can't just use it, and you need to expand it with the expand () method.
how_to_get_coeff_from_fractional_expression.py
# coding:utf-8
import sympy as sp
# f(x)/g(y)X of**How to take the order of a
#Create a sympy variable
x, y = sp.symbols('x y')
# sympy.Create a Symbol function (division formula)
symbolFunc = (x**2 + 2*x + 3) / (4*y + 5)
# x**As a coefficient of 1, 2/(4y + 5)Expects but becomes 0
print(symbolFunc.coeff(x, 1))
# ==> 0
# expand()Biting the method works
print(symbolFunc.expand().coeff(x, 1))
# ==> 2/(4y + 5)
Recommended Posts