Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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}} *)
share|improve this answer
    
Nice answer (I voted for it too). But also see responses and comments to this stack overflow related question –  Daniel Lichtblau Jun 3 '12 at 20:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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