MathGroup Archive 1999

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18892] Re: How can I plot the region satisfying an inequality?
  • From: phbrf at t-online.de (Peter Breitfeld)
  • Date: Sun, 25 Jul 1999 03:30:21 -0400
  • Organization: das ist ein breites Feld ...
  • References: <7mp3dn$l99@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

ELodger <elodger at my-deja.com> 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 :-)
----------------8<----------------8<----------------
InequalityPlot::usage=
"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 =
      Table[
        FilledPlot[a[[i]][[2]], a[[i]][[1]],
						DisplayFunction -> Identity, opts],
		  {i, 1, Length[a]}];
    Show[plots, DisplayFunction -> $DisplayFunction];
]

SetAttributes[InequalityPlot,ReadProtected]
Protect[InequalityPlot]
----------------8<----------------8<---------------- 

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
-- 
=--=--=--=--=--=--=--=--=--=--=--=--= http://home.t-online.de/home/phbrf
  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?