作者:超级无敌智慧星在路上 | 来源:互联网 | 2023-12-11 09:20
Ihaveapolynomial(generatedfromthecharacteristicpolynomialofamatrix)andIdliketosolve
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:
然而,当使用diop_linear(p)时,期望输入多项式是整数系数类型。尽管查看了文档,但我不确定如何使用sympy 0.75进行此操作。追溯是:
Traceback (most recent call last):
File "test.py", line 8, in
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
1 个解决方案