Using Solve for Objective function max/min [closed]

I have an objective function

z = 4 x + 2 y

with constraints of

x + 2 y >= 4 && 3 x + y >= 7 && -x + 2 y <= 7 && x >= 0 && y >= 0

(Answer for this particular set of constraints should show a minimum of 10 and no maximum value or that the max is a function z = 4 x, either are fine.)

I tried using Solve :

Solve[z == 4 x + 2 y && x + 2 y >= 4 && 3 x + y >= 7 && -x + 2 y <= 7 && x >= 0 && y >= 0, Reals]

which outputs:

Out[2]= {{x -> ConditionalExpression[1/4 (-2 y + z),
(10 < z <= 12 && 28 + 2 y - 3 z <= 0 && -16 + 6 y + z >= 0) ||
(12 < z <= 16 && -16 + 6 y + z >= 0 && -28 + 10 y – z <= 0) || (z > 16 && -28 + 10 y – z <= 0 && y >= 0)]},
{x -> 2, y -> 1, z -> 10}}

This is fine and dandy for the particular example since the second part has the minimum value I was looking for, but for my application, the coefficients will be able to be changed by the user. While testing it, sometimes Solve only had the ConditionalExpression when I expected it to show the z minimum value similar to the above output.

So my question is this. Am I using Solve incorrectly and I’m just missing something, or is there a different function that would be more suitable for me to use to get a minimum and/or maximum value for z?

=================

=================

1 Answer
1

=================

Use Minimize. It will give you the analytical solution:

Minimize[{4 x + 2 y,
x + 2 y >= 4 && 3 x + y >= 7 && -x + 2 y <= 7 && x >= 0 &&
y >= 0}, {x, y}]

Output:

{10,{x->2,y->1}}

For Problems that require heuristical optimization or can’t be solved analytically, use FindMinimum

  

 

Thank you, this worked. I have to check both max and min, so for Maximize, I had to wrap with Quiet since there’s an error when it is unbounded.
– J_Nat
Aug 2 at 14:34