Bug introduced in 9.0 and fixed in 9.0.1
In Mathematica 7 it is very easy to conditionally suppress plotting of individual lines using If:
Plot[{
If[x^2 < 2, x^2],
If[Exp[x] > x^2, Exp[x]],
If[False, x] (* check recommended by Rahul *)
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]

Or more verbosely using Piecewise and Indeterminate:
Plot[{
Piecewise[{{x^2, x^2 < 2}}, Indeterminate],
Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate],
Piecewise[{{x, False}}, Indeterminate] (* check recommended by Rahul *)
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]

It is reported that neither method works in version 9.0.0 (at least on OSX.) Furthermore it is reported that my attempt using ConditionalExpression also fails:
Plot[{
ConditionalExpression[x^2, x^2 < 2],
ConditionalExpression[Exp[x], Exp[x] > x^2]
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]
Plotting a zero is reported to "work" but that is hardly a solution:
Plot[{
Piecewise[{{x^2, x^2 < 2}}],
Piecewise[{{Exp[x], Exp[x] > x^2}}]
},
{x, -2, 2},
PlotStyle -> Thick, Frame -> True]

1. Is this indeed a bug in version 9.0.0?
2. Is there a workaround for the affected systems?
Answer
Since this bug seems to be tied directly to the appearance of Indeterminate as the only available function value in the plot range, it could perhaps be considered a work-around to replace Indeterminate by another "quantity" that behaves the same way as Indeterminate but doesn't cause the whole display of all other functions to be suppressed.
I tried the following, and it works on version 9.0.0:
Plot[{Piecewise[{{x^2,x^2<2}},Indeterminate],
Piecewise[{{Exp[x],Exp[x]>x^2}},Indeterminate],
Piecewise[{{x,False}},I] (*modified check recommended by Rahul*)},
{x,-2,2},
PlotStyle->Thick,Frame->True]
Here, I used the imaginary unit I to produce the same effect as Indeterminate, and the remaining plots do still get displayed.
To make this more general, maybe one can use a replacement rule like this:
Plot[Evaluate[{Piecewise[{{x^2, x^2 < 2}}, Indeterminate],
Piecewise[{{Exp[x], Exp[x] > x^2}}, Indeterminate],
Piecewise[{{x, False}},
Indeterminate] (*modified check recommended by Rahul*)} /.
Indeterminate -> I], {x, -2, 2}, PlotStyle -> Thick, Frame -> True]
Comments
Post a Comment