Reputation: 88198
I have a polynomial (generated from the characteristic polynomial of a matrix) and I'd like to solve for the integer solutions
import sympy
from sympy.solvers.diophantine import diop_linear
M = sympy.Matrix([[0,1,1],[1,0,1],[1,1,0]])
p = M.charpoly()
This polynomial clearly factors into integer roots:
print p.factor()
# (_lambda - 2)*(_lambda + 1)**2
The input polynomial however, is expected to be an integer coefficient type when using diop_linear(p)
. I'm not sure how to do this using sympy 0.75, despite looking through the docs. The traceback is:
Traceback (most recent call last):
File "test.py", line 8, in <module>
diop_linear(p)
File "/usr/local/lib/python2.7/dist-packages/sympy/solvers/diophantine.py", line 365, in diop_linear
var, coeff, diop_type = classify_diop(eq)
File "/usr/local/lib/python2.7/dist-packages/sympy/solvers/diophantine.py", line 232, in classify_diop
raise TypeError("Coefficients should be Integers")
TypeError: Coefficients should be Integers
Upvotes: 2
Views: 983
Reputation: 91580
That error message is clearly incorrect. The problem is that diop_linear
only works for linear diophantine equations (which for single variable equations are not that interesting). If you just want to solve a single variable equation, just use solve
.
Upvotes: 1