4
$\begingroup$

I want to solve a quadratic integer programming problem in Mathematica. My first attempt looks like this:

Minimize[{0.21 (2 x/40)^2 + 0.15 (10 y/40)^2 - 2*(2 x/40)*(10 y/40)*0.05, 
2 x + 10 y == 40 && x > 0 && y > 0 && Element[x | y, Integers]}, {x,y}]

The output is:

NMinimize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

And:

{0.07875, {x -> 5, y -> 3}}

But it seems not very optimal (e.g. for x=10 and y=2 we get 0.065). I know that integer programming can be tough, but I think this kind of problems should be somehow solvable in Mathematica. Probably I just use wrong commands to achieve this. How can I go about it?

$\endgroup$
10
$\begingroup$

From the documentation of Minimize:

If Minimize is given an expression containing approximate numbers, it automatically calls NMinimize.

To get around this you could rationalize the equations first, e.g.

Minimize[{Rationalize[0.21 (2 x/40)^2 + 0.15 (10 y/40)^2 - 2*(2 x/40)*(10 y/40)*0.05], 
  2 x + 10 y == 40 && x > 0 && y > 0 && Element[x | y, Integers]}, {x, y}]

(* output: {13/200, {x -> 10, y -> 2}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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