Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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}]
share|improve this answer
    
Well that would be simpler.... +1 –  Mr.Wizard Feb 27 '13 at 10:13
add comment

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

Mathematica graphics

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

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.