2
$\begingroup$

I have three inequalities that are below

$3x-4y\leq 12,$

$3x+2y\geq 6,$

$x+2y\leq 10,$

$x\geq 0$

$ y \geq 0$

I know how to plot linear equation in mathematica. The feasible solution region of these inequalities has been plot in figure in book as, I am interseted to plot the feasible solution of the region as plotted in book using mathematica. How can I plot and indicates each and everything shown in Figure. enter image description here

$\endgroup$
  • $\begingroup$ Please do not use inappropriate tags. None of the tags you used is related in any way to the question. Look up RegionPlot and ContourPlot. $\endgroup$ – Szabolcs Apr 7 at 8:28
1
$\begingroup$
constraints = {3 x - 4 y <= 12, 3 x + 2 y >= 6, x + 2 y <= 10, x >= 0, y >= 0};

ticklabels = {x, y} /. Solve[And[Or @@ eqs[[{1, 2, 3}]], 
       DeleteCases[{x, y}, #] == 0], {x, y}] & /@ {x, y};

tickf = {#, Framed[Style[#, 16] &@Row[{"(", #2, ",", #3, ")"}], 
     FrameStyle -> None, Background -> White]} &;

xticks = tickf[#, ##] & @@@ ticklabels[[1]];
yticks = tickf[#2, ##] & @@@ ticklabels[[2]];

Show[RegionPlot[And @@ constraints, {x, -8, 15}, {y, -5, 12},
  PlotPoints -> 100, PlotStyle -> LightRed, 
  PlotLegends -> SwatchLegend[{"feasible"}, LegendMarkerSize -> 20]],
 ContourPlot[Evaluate[Equal @@@ constraints[[;; -3]]], {x, -8, 15}, {y, -5, 12}, 
   ContourStyle -> (Arrowheads[{{-.04, 0}, {.04, 1}, {.7, .85, 
      Graphics@ Text[Style[#, 14], {0, 0}, 
       {0, 1.5  (#[[1, 2]] /. {10 -> 1, 12 | 6 -> -1})},
       {(#[[1, 2]] /. {10 | 6 -> -1, 12 -> 1}), 0}]}}] & /@ 
         (HoldForm /@ constraints[[;; 3]])),
   MeshFunctions -> {# &, #2 &}, Mesh -> {{0}, {0}}, 
   MeshStyle -> AbsolutePointSize[10], BaseStyle -> Thick,
   PlotLegends -> LineLegend[97, Equal @@@ constraints]] /. Line -> Arrow, 
 Axes -> True, Frame -> False, 
 Ticks -> {xticks, yticks},
 TicksStyle -> Directive[Thin, Black, FontSize -> Medium],
 AxesStyle -> (Directive[Thick, Arrowheads[{-.04, .04}], ColorData[97]@#] & /@ {4, 5}), 
 Method -> {"AxesInFront" -> False}, PlotRange -> All, ImageSize -> Large]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Can we show the corner points brother also as shown in figure which I have added? $\endgroup$ – Noor Aslam Apr 7 at 17:20
  • $\begingroup$ @Noor, please see the updated version. $\endgroup$ – kglr Apr 7 at 23:27
  • $\begingroup$ Thanks brother but not running in my system, do not know why? $\endgroup$ – Noor Aslam Apr 8 at 5:50
2
$\begingroup$

As @Szabolcs suggested, you can use RegionPlot (for the region) and ContourPlot for the boundarylines,

plot1 = ContourPlot[{3 x - 4 y == 12, 3 x + 2 y == 6, x + 2 y == 10},
                    {x, -10, 10}, {y, -10, 10}, Axes -> True]
plot2 = RegionPlot[{3 x - 4 y <= 12 && 3 x + 2 y >= 6 && x + 2 y <= 10 && 
                    x >= 0 && y >= 0}, {x, -10, 10}, {y, -10, 10}, Axes -> True]
Show[plot1,plot2] (*to combine them*)

enter image description here

You can get the corner points by solving the equations. For example

Solve[3 x - 4 y == 12 && 3 x + 2 y == 6, {x, y}]

{{x->8/3,y->-1}}

gives the intercepts between blue and orange line. Similarly you can get the intercepts of a line and axis and combine the points with ListPlot.

| improve this answer | |
$\endgroup$
  • $\begingroup$ What to do to show the corner points? $\endgroup$ – Noor Aslam Apr 7 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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