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'trying to do an embarrassingly simple linear programming problem, and being a total Mathematica and maths analphabet I'm stuck. The problem is to optimize (maximize) the function $1.2x+y$, with constraints:

$$ 10x+12y\leq1920 \\ 5x+3y\leq780 \\ x,y\geq0 $$

Doing it by hand, or like this:

Maximize[{1.2 x + y, 10 x + 12 y <= 1920 && 5 x + 3 y <= 780 && x >= 0 && y >= 0}, {x, y}]

I get the correct answer of $x=120,y=60$.

But when I try to calculate it using LinearProgramming, like this:

 {1.2, 1},
 {{10, 12}, {5, 3}},
 {{1920, -1}, {780, -1}},
 {{0, Infinity}, {0, Infinity}}]

I get $x=0,y=0$ as an answer. I've been staring at the LinearProgramming documentation for an hour and can't find the error.

If I switch from {{1920, -1}, {780, -1}} to {{1920, 1}, {780, 1}} it gives the correct answer, but according to the docs it's then testing for $\geq$, and not for $\leq$, as my problem states.

Any idea what am I doing wrong here? Thanks...

share|improve this question

closed as off-topic by bobthechemist, Pickett, ciao, ubpdqn, m_goldberg Mar 15 '14 at 3:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bobthechemist, Pickett, ciao, ubpdqn, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

LinearProgramming minimizes, you'll get same if you use Minimize in your first example, or switch inequalities in same to opposites. –  ciao Mar 15 '14 at 0:03
@rasher thanks, I don't know how I came up with maximization, it's not event mentioned anywhere in the docs for LinearProgramming! –  klzzvn Mar 15 '14 at 12:15
@rasher switching inequalities will not work -- see my answer below. –  A.G. Mar 15 '14 at 16:32

1 Answer 1

up vote 3 down vote accepted

To maximize c.x, minimize -c.x:

 {-1.2, -1},
 {{10, 12}, {5, 3}},
 {{1920, -1}, {780, -1}},
 {{0, Infinity}, {0, Infinity}}]

(* {120., 60.} *)
share|improve this answer

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