MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How can I plot the region satisfying an inequality?

ELodger <elodger at> schrieb:
> Hi There,
> Is there a way to plot the region satisfying a set of inequalities,
> such as:
> x - y > 0 and
> x + y < 0
> on [-10, 10]

I have a Function to do this. It requires Algebra`InequalitySolve` and
Graphics`FilledPlot` to work. Sorry for the german usage, but I just
copied it :-)
"InequalityPlot[ungl,{x,xmin,xmax},{y,ymin,ymax},(opts)] zeichnet das
Loesungsgebiet der Ungleichung `ungl' in den beiden Variablen `x' und `y'
innerhalb des angegebenen Gebiets. Die Ungleichungen mussen der Syntax
von `InequalitySolve' gehorchen. Moegliche Optionen sind die fur
`FilledPlot' erlaubten."

InequalityPlot[ungl_, {x_, xmin_, xmax_}, {y_, ymin_, ymax_},opts___] :=
Module[{lsg, ur, plots, i, a, b},
    lsg = InequalitySolve[(ungl) && (xmin <= x <= xmax) &&
           (ymin <= y <= ymax),{x, y}];
    ur = ((List @@ lsg) /. LessEqual -> Less);
    ur = ur //.
        {Inequality[a_, Less, x, Less, b_] -> {x, a, b},
          Inequality[a_, Less, y, Less, b_] -> {a, b},
          And[a_, b__] -> {a, b},
          {a_, HoldPattern[Or[b__]]} :> ({a, #} &) /@ {b} };
    b = Position[{ur}, {{_, _, _}, {_, _}}];
    a = Table[Extract[{ur}, b[[i]] ], {i, 1, Length[b]}];
    plots =
        FilledPlot[a[[i]][[2]], a[[i]][[1]],
						DisplayFunction -> Identity, opts],
		  {i, 1, Length[a]}];
    Show[plots, DisplayFunction -> $DisplayFunction];


For your example you enter:
In:= InequalityPlot[x-y>0 && x+y<0, {x,-10,10},{y,-10,10}];

I don't know if there are still some bugs in it, but it works for your
example and a lot of others I used it for.
I used `Extract' in the code wich is new to Mathematica 4 IIRC, but you can use
`Part' instead with slightly change of the syntax to make it work on Mathematica 3
as well.

When testing this function, I realized, that InequalitySolve returns only
Inequalities in Less and LessEqual. Can the gurus in this group confirm
this observation?

Gruss, Peter
  Peter Breitfeld, Saulgau, Germany        PGP public key:  08548045

  • Prev by Date: Re: Menu Control
  • Next by Date: Re: data acquisition system with mathematica 3.0
  • Previous by thread: Re: How can I plot the region satisfying an inequality?
  • Next by thread: Re: How can I plot the region satisfying an inequality?