# Invalid comparison in RegionPlot

I'm trying to plot something like this:

RegionPlot[0 < (.5*a2 - .25*a1)/(a2 - a1) < 1 && 0 < a1 < a2 < 1, {a1, 0, 1}, {a2, 0, 1}]


The above code yields an error message (it tries to use 1/0 in the inequality). I can solve the problem by simply starting the plot at an arbitrarily low value of a2. My question is: is there a more "elegant" way of doing that? I would expect the inequality 0 < a1 < a2 < 1 to take care of that.

-

Usually, when you have a && b then b is not evaluated if a already returned False. Using this, the incredibly easy answer is

RegionPlot[
0 < a1 < a2 < 1 && 0 < (.5*a2 - .25*a1)/(a2 - a1) < 1,
{a1, 0, 1}, {a2, 0, 1}]

-
Well that would be simpler.... +1 – Mr.Wizard Feb 27 '13 at 10:13

If the issue is simply the printing of the error messages you can suppress them with Quiet:

RegionPlot[
Quiet[0 < (.5*a2 - .25*a1)/(a2 - a1) < 1 && 0 < a1 < a2 < 1],
{a1, 0, 1},
{a2, 0, 1}
]


You could also define a function that prevents this condition:

f[a1_, a2_] /; a1 == a2 := False

f[a1_, a2_] := 0 < (.5*a2 - .25*a1)/(a2 - a1) < 1 && 0 < a1 < a2 < 1

RegionPlot[
f[a1, a2],
{a1, 0, 1},
{a2, 0, 1}
]


-