系数应为整数:syy diophantine方程

时间:2021-02-19 20:23:00

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 <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

1 个解决方案

#1


1  

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.

该错误消息显然不正确。问题是diop_linear仅适用于线性不定方程(对于单变量方程而言,它并不那么有趣)。如果您只想解决单变量方程,只需使用solve即可。

#1


1  

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.

该错误消息显然不正确。问题是diop_linear仅适用于线性不定方程(对于单变量方程而言,它并不那么有趣)。如果您只想解决单变量方程,只需使用solve即可。