Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. >>


{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
up vote 10 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


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.