How to solve a degenerate system of equations in sympy

被刻印的时光 ゝ 提交于 2019-12-10 16:24:34

问题


I have lots of systems of equations, some are underspecified, and I would like to find one non-zero solution if it exists or report that there are none. However, sympy seems to hang trying to find all solutions. Here is an extreme example.

from sympy import *
A = Matrix([
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
])
syms = symbols("x:12")
s = Matrix(syms)
constraints = [xi**3 - xi for xi in syms]
solve(list(A*s) + constraints, syms)

How can I get sympy to just report one non-zero solution quickly in an example like this? In fact I would be happy if it just reported that there was a solution.

来源:https://stackoverflow.com/questions/20825782/how-to-solve-a-degenerate-system-of-equations-in-sympy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!