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