I'm studying the behavior of the branch and bound algorithm in a integer 2-variable linear problem. I occasionally use Wolfram Alpha for plotting graphs, but now I need a more robust option, Mathematica. I need to plot the viable zone of a set of inequalities on the R2 space (with x and y greater than 0), inequalities such as:
2*x+4*y <= 12 // 6*x+2*y <= 27 // x <= 4 // x>=0 // y>=0
The graph must show all integer x,y points on the positive quadrant (I think a mesh function can do this) and a specific point (solution of the max/minimization problem) For example, the viable space in this case is: http://www.wolframalpha.com/input/?i=plot%282*x%2B4*y%3C%3D12%2C6*x%2B2*y%3C%3D27%2Cx%3C%3D4%2Cx%3E%3D0%2Cy%3E%3D0%29
thanks in advance.
The function you are looking for is RegionPlot
:
RegionPlot[
2 x + 4 y <= 12 && 6 x + 2 y <= 27 && x <= 4 && x >= 0 && y >= 0, {x,
0, 5}, {y, 0, 5}]
To make a nice-looking plot over the integer points the inequality satisfies, here is a function to plot it:
IntegerRegionPlot[quantifier_, {xmin_, xmax_}, {ymin_, ymax_}] :=
Graphics[Flatten[
Table[If[
quantifier, {Red, Disk[{x, y}, 0.5]}, {Blue,
Disk[{x, y}, 0.5]}], {x, xmin, xmax}, {y, ymin, ymax}]],
Frame -> True];
To plot the inequality, just do this:
IntegerRegionPlot[
2 x + 4 y <= 12 && 6 x + 2 y <= 27 && x <= 4 && x >= 0 && y >= 0, {0,
5}, {0, 5}]