2
$\begingroup$

I generate a list of equations by this command:

lines = Flatten[Table[Cos[alpha] x + Sin[alpha] y == c, {alpha, 0, 2 Pi, Pi / 2}, {c, 0, 10, 5}]]

This correctly returns the list of line equations in plane:

{x == 0, x == 5, x == 10, y == 0, y == 5, 
 y == 10, -x == 0, -x == 5, -x == 10, -y == 0, -y == 5, -y == 10, 
 x == 0, x == 5, x == 10}

However, when i call ContourPlot[lines, {x, -10, 10}, {y, -10, 10}], nothing is displayed.

But when I copy the result list directly into the ContourPlot like this:

ContourPlot[{x == 0, x == 5, ... , x == 10}, {x, -10, 10}, {y, -10, 10}]

Then the lines are plotted correctly.

I am quite new to Mathematica, and I am not really sure what causes this problem. It is quite probable that I misunderstood something, so I will appreciate help of more advanced users.

$\endgroup$
1
  • $\begingroup$ ContourPlot[Evaluate@lines, {x, -10, 10}, {y, -10, 10}] Compare Trace[ContourPlot[lines, {x, -10, 10}, {y, -10, 10}], ContourPlot] with Trace[ContourPlot[Evaluate@lines, {x, -10, 10}, {y, -10, 10}], ContourPlot] $\endgroup$
    – Feyre
    Jan 31 '17 at 13:24
2
$\begingroup$

This is a common beginner problem. All Mathematica plotting functions do not evaluate their arguments normally because they have been given the attribute HoldAll. That means you must give pass them the entire expression or pre-evaluate the symbol holding the expression. Try

ContourPlot[Evaluate[lines], {x, -10, 10}, {y, -10, 10}]

which will work.

$\endgroup$

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