3
$\begingroup$

I need to find one non-negative solution to the system of linear equations

y[9]==0&&y[8]==1-2 y[12]&&y[7]==3-2 y[11]-3 y[14]&&y[6]==-2 y[10]-3 y[13]-4 y[15]&&y[5]==0&&y[4]==1&&y[3]==1+y[12]&&y[2]==y[11]+2 y[14]&&y[1]==1+y[10]+2 y[13]+3 y[15]&&x[15]==0&&x[14]==1+y[15]&&x[13]==-y[15]&&x[12]==y[14]-y[15]&&x[11]==2+y[13]-y[14]+3 y[15]&&x[10]==-y[13]-2 y[15]&&x[9]==y[12]-y[14]&&x[8]==y[11]-y[12]-y[13]+3 y[14]-2 y[15]&&x[7]==3+y[10]-y[11]+3 y[13]-2 y[14]+5 y[15]&&x[6]==-y[10]-2 y[13]-3 y[15]&&x[5]==-y[12]&&x[4]==1-y[11]+y[12]-2 y[14]&&x[3]==-1-y[10]+y[11]-2 y[13]+2 y[14]-3 y[15]&&x[2]==1+y[10]+2 y[13]+3 y[15]&&x[1]==0 

I tried to use FindInstance to solve it, but it is too complicated.

I wonder whether there are other more efficient methods that utilize the linearity.

$\endgroup$
3
  • $\begingroup$ Do you mean all of the x[i] are non-negative for arbitrary y[j]? $\endgroup$ Commented Jul 30 at 8:04
  • $\begingroup$ No. All of x[i]s and y[i]s need to be non-negative. @CraigCarter $\endgroup$ Commented Jul 30 at 9:02
  • $\begingroup$ Set {x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13], x[14], x[15], y[1], y[2], y[3], y[4], y[5], y[6], y[7], y[8], y[9], y[10], y[11], y[12], y[13], y[14], y[15]} >= 0. $\endgroup$ Commented Aug 1 at 2:28

3 Answers 3

6
$\begingroup$

There is one and only solution in non-negative reals and that is probably why FindInstance has problems with it. FindInstance is good for cases where there are lots of solutions and you need few of them.

If you use Solve you get the solution in no time.

Solve[y[9] == 0 && y[8] == 1 - 2 y[12] && y[7] == 3 - 2 y[11] - 3 y[14] && y[6] == -2 y[10] - 3 y[13] - 4 y[15] && y[5] == 0 && y[4] == 1 && y[3] == 1 + y[12] && y[2] == y[11] + 2 y[14] && y[1] == 1 + y[10] + 2 y[13] + 3 y[15] && x[15] == 0 && x[14] == 1 + y[15] && x[13] == -y[15] && x[12] == y[14] - y[15] && x[11] == 2 + y[13] - y[14] + 3 y[15] && x[10] == -y[13] - 2 y[15] && x[9] == y[12] - y[14] && x[8] == y[11] - y[12] - y[13] + 3 y[14] - 2 y[15] && x[7] == 3 + y[10] - y[11] + 3 y[13] - 2 y[14] + 5 y[15] && x[6] == -y[10] - 2 y[13] - 3 y[15] && x[5] == -y[12] && x[4] == 1 - y[11] + y[12] - 2 y[14] && x[3] == -1 - y[10] + y[11] - 2 y[13] + 2 y[14] - 3 y[15] && x[2] == 1 + y[10] + 2 y[13] + 3 y[15] && x[1] == 0, NonNegativeReals] 

{{x[1] -> 0, x[2] -> 1, x[3] -> 0, x[4] -> 0, x[5] -> 0, x[6] -> 0, x[7] -> 2, x[8] -> 1, x[9] -> 0, x[10] -> 0, x[11] -> 2, x[12] -> 0, x[13] -> 0, x[14] -> 1, x[15] -> 0, y[1] -> 1, y[2] -> 1, y[3] -> 1, y[4] -> 1, y[5] -> 0, y[6] -> 0, y[7] -> 1, y[8] -> 1, y[9] -> 0, y[10] -> 0, y[11] -> 1, y[12] -> 0, y[13] -> 0, y[14] -> 0, y[15] -> 0}} 
$\endgroup$
3
$\begingroup$

Does this suffice?

eqs = List @@ (y[9] == 0 && y[8] == 1 - 2 y[12] && y[7] == 3 - 2 y[11] - 3 y[14] && y[6] == -2 y[10] - 3 y[13] - 4 y[15] && y[5] == 0 && y[4] == 1 && y[3] == 1 + y[12] && y[2] == y[11] + 2 y[14] && y[1] == 1 + y[10] + 2 y[13] + 3 y[15] && x[15] == 0 && x[14] == 1 + y[15] && x[13] == -y[15] && x[12] == y[14] - y[15] && x[11] == 2 + y[13] - y[14] + 3 y[15] && x[10] == -y[13] - 2 y[15] && x[9] == y[12] - y[14] && x[8] == y[11] - y[12] - y[13] + 3 y[14] - 2 y[15] && x[7] == 3 + y[10] - y[11] + 3 y[13] - 2 y[14] + 5 y[15] && x[6] == -y[10] - 2 y[13] - 3 y[15] && x[5] == -y[12] && x[4] == 1 - y[11] + y[12] - 2 y[14] && x[3] == -1 - y[10] + y[11] - 2 y[13] + 2 y[14] - 3 y[15] && x[2] == 1 + y[10] + 2 y[13] + 3 y[15] && x[1] == 0) 

variables:

yvars = Union@Cases[eqs, y[_], Infinity] xvars = Union@Cases[eqs, x[i_], Infinity] 

target:

eqsAndCons = Join[eqs, y[#] >= 0 & /@ Range[15], x[#] >= 0 & /@ Range[15]] 

instance:

fi=FindInstance[eqsAndCons, Join[yvars, xvars], Reals ] (*{{y[1] -> 1, y[2] -> 1, y[3] -> 1, y[4] -> 1, y[5] -> 0, y[6] -> 0, y[7] -> 1, y[8] -> 1, y[9] -> 0, y[10] -> 0, y[11] -> 1, y[12] -> 0, y[13] -> 0, y[14] -> 0, y[15] -> 0, x[1] -> 0, x[2] -> 1, x[3] -> 0, x[4] -> 0, x[5] -> 0, x[6] -> 0, x[7] -> 2, x[8] -> 1, x[9] -> 0, x[10] -> 0, x[11] -> 2, x[12] -> 0, x[13] -> 0, x[14] -> 1, x[15] -> 0}}*) 

Check:

Union[Flatten[eqs /. fi]] (*{True}*) 
$\endgroup$
1
$\begingroup$

Indeed, we can solve it as a linear optimization problem.

First convert the equations to a list, include the non-negativity condition, and call the LinearOptimization function.

cons1=y[9]==0&&y[8]==1-2 y[12]&&y[7]==3-2 y[11]-3 y[14]&&y[6]==-2 y[10]-3 y[13]-4 y[15]&&y[5]==0&&y[4]==1&&y[3]==1+y[12]&&y[2]==y[11]+2 y[14]&&y[1]==1+y[10]+2 y[13]+3 y[15]&&x[15]==0&&x[14]==1+y[15]&&x[13]==-y[15]&&x[12]==y[14]-y[15]&&x[11]==2+y[13]-y[14]+3 y[15]&&x[10]==-y[13]-2 y[15]&&x[9]==y[12]-y[14]&&x[8]==y[11]-y[12]-y[13]+3 y[14]-2 y[15]&&x[7]==3+y[10]-y[11]+3 y[13]-2 y[14]+5 y[15]&&x[6]==-y[10]-2 y[13]-3 y[15]&&x[5]==-y[12]&&x[4]==1-y[11]+y[12]-2 y[14]&&x[3]==-1-y[10]+y[11]-2 y[13]+2 y[14]-3 y[15]&&x[2]==1+y[10]+2 y[13]+3 y[15]&&x[1]==0; cons1=cons1/.And->List; vars=Flatten@Table[{x[i], y[i]}, {i, 1, 15}]; cons2=#>=0&/@vars; cons=Union[cons1,cons2]; LinearOptimization[0,cons,vars] 

The result is

{x[1]->0,y[1]->1,x[2]->1,y[2]->1,x[3]->0,y[3]->1,x[4]->0,y[4]->1,x[5]->0,y[5]->0,x[6]->0,y[6]->0,x[7]->2,y[7]->1,x[8]->1,y[8]->1,x[9]->0,y[9]->0,x[10]->0,y[10]->0,x[11]->2,y[11]->1,x[12]->0,y[12]->0,x[13]->0,y[13]->0,x[14]->1,y[14]->0,x[15]->0,y[15]->0} 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.