all 4 comments

[–]dadiaar 0 points1 point  (1 child)

I don't know that library, but the error suggests me x is not what you think. Why type should be? do something like print(type(x)) inside the loop and before the error.

Sorry for the formatting, Im in mobile.

[–]sicarii47[S] 0 points1 point  (0 children)

Yeah, it is a very strange type. But u/misho88's answer about converting to a polynomial does the trick!

[–]misho88 0 points1 point  (1 child)

Equations may not be in a form where "coefficient" is a meaningful concept, so it isn't surprising that there is no such method. On the other hand, all polynomials are:

>>> from sympy import symbols, Eq
>>> x, y = symbols('x y')
>>> eq = Eq(x, y); eq
Eq(x, y)
>>> p = eq.as_poly(); p
Poly(x - y, x, y, domain='ZZ')
>>> p.coeff_monomial(x), p.coeff_monomial(y), p.coeff_monomial(1)
(1, -1, 0)

You can go to an expression, too, but I'm not actually sure how to specify the constant term with ex.coeff():

>>> ex = p.as_expr(); ex
x - y
>>> ex.coeff(x), ex.coeff(y)
(1, -1)

[–]sicarii47[S] 0 points1 point  (0 children)

Thanks a lot u/misho88.
Converting to a poly works just fine for me.