0
$\begingroup$

How to perform linear programming in Mathematica based on the following conditions, to draw the feasible region defined by -1 <= a + b <= 1 and 1 <= a - b <= 3, and find the range of t==3 a-b

The range of t can be solved using Reduce.

Reduce[{-1 <= a + b <= 1, 1 <= a - b <= 3, t == 3 a - b}, t, {a, 
  b}, Reals]

The current requirement is to use linear programming to solve for the feasible region under the given conditions, with the feasible region being shaded for identification. The objective function crosses the feasible region, and the range problem is solved using graphical methods.

My personal attempt is as follows.

inequalities = {-1 <= a + b <= 1, 1 <= a - b <= 3};
RegionPlot[Evaluate@inequalities, {a, -5, 5}, {b, -5, 5}, 
 PlotStyle -> Directive[Opacity[0.5], LightBlue], 
 FrameLabel -> {"a", "b"}, PlotLegends -> "Expressions"]
targetFunction = b == 3 a - t;
solution = Reduce[Join[inequalities, {targetFunction}], {a, b, t}]

The issue is that the feasible region is not shaded for identification, which feels quite cumbersome. Is there a better way to solve this problem?

$\endgroup$
1
  • $\begingroup$ How about replacing your first line by inequalities = (-1 <= a + b <= 1 && 1 <= a - b <= 3); ? $\endgroup$
    – A. Kato
    Commented Jul 19 at 1:35

1 Answer 1

4
$\begingroup$

Look up the documentation for constrained minimization/maximization:

s = {3 a - b, -1 <= a + b <= 1 && 1 <= a - b <= 3};

Minimize[s, {a, b}]
(*    {1, {a -> 0, b -> -1}}    *)

Maximize[s, {a, b}]
(*    {7, {a -> 2, b -> -1}}    *)

So the range for $t=3a-b$ is $[1,7]$.

Auto-discovering the variables works too:

Minimize[s, Variables[s]]
(*    {1, {a -> 0, b -> -1}}    *)

Maximize[s, Variables[s]]
(*    {7, {a -> 2, b -> -1}}    *)

Or go directly to linear programming (which is the same, in the background):

t = 3 a - b;
cons = {-1 <= a + b <= 1, 1 <= a - b <= 3};

LinearOptimization[t, cons, {a, b}]
(*    {a -> 0, b -> -1}    *)

LinearOptimization[-t, cons, {a, b}]
(*    {a -> 2, b -> -1}    *)
$\endgroup$
1
  • 1
    $\begingroup$ excellent ! LinearOptimization ideal. +1 $\endgroup$
    – ubpdqn
    Commented Jul 19 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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