1
$\begingroup$
z = Array[Subscript[y, ##] &, {3, 2}]
f = {2, 5, 1}
z*f
Total[Flatten[ z*f]]
Minimize[{Total[Flatten[ z*f]], 
  Total[z] == 10 && NonNegative[Min[z]]}, z, Integers]

The above code works for one-dimensional matrix z, But when z is two-dimensional, this error occurs:

Minimize::ivar: {Subscript[y, 1,1],Subscript[y, 1,2]} is not a valid variable. >>

Anyone have any idea why this happens?

Thanks

$\endgroup$

1 Answer 1

2
$\begingroup$

One has to provide the variables as a flat list. Therefore you just have to replace z with Flatten[z] in your Minimize:

Minimize[{Total[Flatten[z*f]], Total[z] == 10 && NonNegative[Min[z]]}, Flatten@z, Integers]

Out

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.