热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

系数应为整数:syydiophantine方程-CoefficientsshouldbeIntegers:sympydiophantineequations

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 个解决方案

#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即可。


推荐阅读
author-avatar
超级无敌智慧星在路上
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有