How to solve these equations?

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

It runs long long time, but no results.

Anyone can help me to solve this problem?

help

You have at least the 8 solutions with x,y,z\in\{0,1\}. There are other solutions with x=\frac{c₃ - g₁}{ s₁ +g₁}

Note please that this is really not a Julia question per se, since all SymPy.jl does is call out to Python.

I let it run in the background and forgot all about it, but the solve did finish. Edit: But it took twenty minutes.

julia> @time solve([eq1,eq2,eq3],[x,y,z], domain=SymPy.sympy.S.Reals)
1193.533067 seconds (29.31 M allocations: 333.714 GiB, 0.06% gc time)
10-element Vector{Tuple{Sym, Sym, Sym}}:
 (0, 0, 0)
 (0, 0, 1)
 (0, 1, 0)
 (0, 1, 1)
 (1, 0, 0)
 (1, 0, 1)
 (1, 1, 0)
 (1, 1, 1)
 (-(c₃ - g₁)/(g₁ + s₁), (c₁ - e₁)/(c₂ - e₂ + g₁ + s₁), 0)
 (-(c₃ - g₁)/(g₁ + s₁), (c₁ - c₂ - e₁ + e₂ - g₂)/(g₁ + s₁), 1)

Your fx,... are called eq1,... here, and I asked for real solutions. Although that probably won’t make a difference, because no assumptions about the other variables are made.

1 Like

Thanks, This result is what I want. But I can not get this result. The solve can not finish. I run for one day, but it did not finish.

Can I use other package to solve this problem?

Why are solutions calculated only for z=0 and z=1?
It would seem that there are many other (infinite?) solutions.

PS
I just tried to do a quick calculation by hand.

It seems easier to solve them by hand to be honest.

In matlab, it can solve them very quickly. But why Julia can’t?

I have run for 1 hour, it still not finish.

Again, you are not really using Julia here, you are calling SymPy which is a Python library:

https://www.sympy.org/en/index.html

You might have more luck asking about SymPy performance issues on a SymPy forum.

1 Like

Thanks , but How can I use Julia to solve this problem?

Can Julia solve this problem ?

I’ve never used anything but Wolfram tools for symbolic manipulation, but you can try

I try to use Symbolics.jl, but It seems that Symbolics can only solve linear equations.

julia> using Symbolics

julia> @syms x y z e₁ e₂  c₁ c₂ c₃  c₅ s₁ s₂ s₃ g₁ g₂
(x, y, z, e₁, e₂, c₁, c₂, c₃, c₅, s₁, s₂, s₃, g₁, g₂)

julia> 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)
x*(x - 1)*(c₁ + e₂*y + e₂*z + c₂*y*z - e₁ - c₂*y - g₁*y - s₁*y - c₂*z - g₂*z - e₂*y*z)

julia> fy = y*(y - 1)*(c₃ + g₁*x - g₁ + s₁*x)
y*(y - 1)*(c₃ + g₁*x + s₁*x - g₁)

julia> fz = -z*(z - 1)*(-c₅ + s₂ + s₃)
-z*(z - 1)*(s₂ + s₃ - c₅)

julia> Symbolics.solve_for([fx, fy, fz], [x, y, z])
ERROR: AssertionError: islinear
Stacktrace:
 [1] solve_for(eq::Vector{SymbolicUtils.Mul{Number, Int64, Dict{Any, Number}, Nothing}}, var::Vector{SymbolicUtils.Sym{Number, Nothing}}; simplify::Bool, check::Bool)
   @ Symbolics ~/.julia/packages/Symbolics/FGTCH/src/linear_algebra.jl:100
 [2] solve_for(eq::Vector{SymbolicUtils.Mul{Number, Int64, Dict{Any, Number}, Nothing}}, var::Vector{SymbolicUtils.Sym{Number, Nothing}})
   @ Symbolics ~/.julia/packages/Symbolics/FGTCH/src/linear_algebra.jl:96
 [3] top-level scope
   @ REPL[6]:1

okay. I looked better. everything’s clear

if -c5+s2+s3=/=0 it is ok.

Can you help me ? how to use Julia to solve this problem. many thanks

How can I use Symbolics,jl to solve this problem?

Try rewriting the equations like this.

julia> @syms x y z A B C D a b c
(x, y, z, A, B, C, D, a, b, c)


julia> eq1=x*(x-1)*(A*y+B*z+C*z*y+D)
x⋅(x - 1)⋅(A⋅y + B⋅z + C⋅y⋅z + D)

julia> eq2=y*(y-1)*(a*x+b)
y⋅(y - 1)⋅(a⋅x + b)

julia> eq3=z*(z-1)*c
c⋅z⋅(z - 1)

julia> @time solve([eq1,eq2,eq3],[x,y,z], domain=SymPy.sympy.S.Reals)
  1.450638 seconds (257 allocations: 8.133 KiB)
10-element Vector{Tuple{Sym, Sym, Sym}}:
 (0, 0, 0)
 (0, 0, 1)
 (0, 1, 0)
 (0, 1, 1)
 (1, 0, 0)
 (1, 0, 1)
 (1, 1, 0)
 (1, 1, 1)
 (-b/a, -D/A, 0)
 (-b/a, (-B - D)/(A + C), 1)
3 Likes