Message Boards Message Boards


Assigning an equation and then plotting it does not work?

Posted 9 years ago
1 Reply
1 Total Likes

First I assign an equation to cir1:

In[21]:= cir1 = x^2 + y^2 == 1

Out[21]= x^2 + y^2 == 1

then if I plot the equation it works fine

ContourPlot[x^2 + y^2 == 1, {x, -1, 1}, {y, -1, 1}]

But if I try the same thing with the variable cir1, I get a blank graph

ContourPlot[cir1, {x, -1, 1}, {y, -1, 1}]

Am I missing something simple to make that work? Newbie here... Thanks!

POSTED BY: Peter Kipping

Try with

ContourPlot[Evaluate[cir1], {x, -1, 1}, {y, -1, 1}]

ContourPlot (and Plot and most plotting functions) protects its argument from outside assignements of variables. Without this protection the following would not work:

x=1; Plot[ x^2, {x,0,1}]

because it would give Plot[1^2, {x,0,1}]. This (mostly) benign protection can be bypassed with Evaluate, when necessary and with care.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract