Bug introduced in 7.0 and fixed in 9.0.1
The following line works fine:
ContourPlot3D[2 x - y == 0, {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
ContourStyle -> Opacity[0.5], Mesh -> False]
But when I bind the equation 2 x - y == 0
to a variable eq
:
eq = 2 x - y == 0
ContourPlot3D[eq, {x, -10, 10}, {y, -10, 10}, {z, -10, 10},
ContourStyle -> Opacity[0.5], Mesh -> False]
it fails. I also noticed that values are assigned to variables x and y after executing ContourPlot3D. There's something that I don't understand about workings of ContourPlot
. Could anyone explain what's going on and how should I pass the equation in a variable?
UPDATE
As m_goldberg wrote in his answer, in a bug-free Mathematica it is not necessary to defer evaluation so eq = 2 x - y == 0
works fine. The call to Evaluate
is still required. But it seems to me that eq
and 2x - y == 0
should evaluate to the same expression:
In[33]:= eq === 1 + 2 x == 0
Out[33]= True
So what's difference between these two expressions, which causes them to behave differently in ContourPlot3D
? How can I see this difference in Mathematica environment?
x
andy
. $\endgroup$eq
only becomes2x-y==0
when it is evaluated. Before evaluationeq
has headSymbol
(and2x-y==0
has headEqual
).ContourPlot3D
has theHoldAll
attribute, soeq
is passed to it in unevaluated form. My guess is that whenContourPlot3D
tests its first argument to see if it's of the forma==b
, it does so without evaluating it, and so ends up treatingeq
as a numerical function rather than an equality. Certainly aTrace
showseq
being sampled at various points in the volume (almost all of which evaluate toFalse
of course). $\endgroup$