1

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.

4

1 回答 1

1

您正在寻找的功能是RegionPlot

RegionPlot[
 2 x + 4 y <= 12 && 6 x + 2 y <= 27 && x <= 4 && x >= 0 && y >= 0, {x,
   0, 5}, {y, 0, 5}]

在此处输入图像描述

为了在不等式满足的整数点上绘制一个漂亮的图,这里有一个函数来绘制它:

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];

要绘制不等式,只需执行以下操作:

IntegerRegionPlot[
 2 x + 4 y <= 12 && 6 x + 2 y <= 27 && x <= 4 && x >= 0 && y >= 0, {0,
   5}, {0, 5}]

在此处输入图像描述

于 2014-06-18T01:39:25.413 回答