# 方程组求解，计算不出来

``````using SymPy
@syms x y z e₁ e₂  c₁ c₂ c₃  c₅ s₁ s₂ s₃ g₁ g₂
fx = x*(x - 1)*(c₁ + c₂*y*z - c₂*y - c₂*z - e₁ - e₂*y*z + e₂*y +
e₂*z - g₁*y - g₂*z - s₁*y)
fy = y*(y - 1)*(c₃ + g₁*x - g₁ + s₁*x)
fz = -z*(z - 1)*(-c₅ + s₂ + s₃)
solve([fx, fy, fz], [x, y, z])
``````

``````import sympy

x, y, z, e1, e2, c1, c2, c3, c5, s1, s2, s3, g1, g2 = sympy.symbols("x y z e1 e2  c1 c2 c3  c5 s1 s2 s3 g1 g2")

fx = x*(x - 1)*(c1 + c2*y*z - c2*y - c2*z - e1 - e2*y*z + e2*y +
e2*z - g1*y - g2*z - s1*y)
fy = y*(y - 1)*(c3 + g1*x - g1 + s1*x)
fz = -z*(z - 1)*(-c5 + s2 + s3)
sympy.solve([fx, fy, fz], [x, y, z])
``````

Python也算不出来，好奇怪啊，手动算都能很快算出来，为啥python算不出来呢

``````using SymPy
@syms x y z e₁ e₂  c₁ c₂ c₃  c₅ s₁ s₂ s₃ g₁ g₂
fxs = [x, x-1, c₁ + c₂*y*z - c₂*y - c₂*z - e₁ - e₂*y*z + e₂*y + e₂*z - g₁*y - g₂*z - s₁*y]
fys = [y, y-1, c₃ + g₁*x - g₁ + s₁*x]
fzs = [z, z-1, -c₅ + s₂ + s₃]
sols = []
for fx in fxs, fy in fys, fz in fzs
sol = solve([fx, fy, fz], [x, y, z]; set=true)
isempty(sol[1]) || push!(sols, sol)
end
sols
``````

``````10-element Vector{Any}:
(Sym[x, y, z], PyObject {(0, 0, 0)})
(Sym[x, y, z], PyObject {(0, 0, 1)})
(Sym[x, y, z], PyObject {(0, 1, 0)})
(Sym[x, y, z], PyObject {(0, 1, 1)})
(Sym[x, y, z], PyObject {(1, 0, 0)})
(Sym[x, y, z], PyObject {(1, 0, 1)})
(Sym[x, y, z], PyObject {(1, 1, 0)})
(Sym[x, y, z], PyObject {(1, 1, 1)})
(Sym[x, y, z], PyObject {((-c₃ + g₁)/(g₁ + s₁), (c₁ - e₁)/(c₂ - e₂ + g₁ + s₁), 0)})
(Sym[x, y, z], PyObject {((-c₃ + g₁)/(g₁ + s₁), (c₁ - c₂ - e₁ + e₂ - g₂)/(g₁ + s₁), 1)})
``````

2 个赞