Given a vector A=[a_1, a_2, a_3,...,a_n], where a_i are integers, now
solving an equation
∑a_i x_i=0 with x_i>=0, and x_i to be integers.
Using Mathematica, we can write some code like
Solve[A . Table[x[i], {i, n}] = 0 && Table[x[i] > 0, {i, n}], Integers]
But the conditions above Table[x[i] > 0 is not rightly coded. It should be x[1]>0 && x[2]>0 && x[3]>0 &&...x[n]>0. Is there any easy way to write such code?
You want to use
ReducenotSolve, asReducecan handle inequalities. As to turningTable[x[i] > 0, {i, n}]intox[1] > 0 && ... && x[n] > 0that’s straightforward:which uses the short form of
Apply(@@) to turninto
Or, more visually,