Help please
M = 10;
z = Array[x, M]
{x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]}
Gcd = Array[GCD, {M, M}];
Minimize[{ Sum[Gcd[[ x[i], x[j] ]], {i, M}, {j, M}],
And @@ Table[1 <= x[k] <= M, {k, M}]},
z,
Integers]
Part::pspec: Part specification x[1] is neither a machine-sized integer nor a list of machine-sized integers. >>_
Michael E2, thank you!
How to simplify the description a more complex function Sum?
M = 10; z = Array[x, M];
Gcd = Array[GCD, {M, M}];
Gcd1 = Table[GCD[a, b] + 1, {a, M}, {b, M}];
obj[x_?(VectorQ[#, NumericQ] &)] := Sum[Gcd[[x[[i]], x[[j]]]]*Gcd1[[i, j]], {i, M}, {j, M}];
NMinimize[{obj[z], And @@ Table[1 <= x[k] <= M, {k, M}] && z ∈ Integers}, z]
And how to add a constraint alldifferent x[i]? (like AMPL-syntax "subject to all_diff {i in 1..M, j in 1..M : i < j}: x[i] != x[j];")
{1,1,1...1}– Dr. belisarius Nov 15 '14 at 22:33x[i]are integers between 1 and 10.Partis getting unhappy at the fact that thex[i]are being treated as variables, and I don't know how to fix this, so I'd be interested to see what the correct syntax for this is. – DumpsterDoofus Nov 15 '14 at 22:39Gcd[[x[i], x[j]]]? – mlainz Nov 15 '14 at 22:45