1
$\begingroup$

When I try to plot an evaluated equation with contour plot in Mathematica 9, but do so with a variable, the plot is empty, but when I input the evaluated equation itself, the ContourPlot plots correctly. Everything worked fine in Mathematica10.

Here's my equations

table2b = 
  Evaluate[
    Table[
      Evaluate@eq2, {P, {-4, -2, 0, 2, 4}}, {n, {.1, .1}}, {α, {1, 1}}, {ρ, {.1, .1}}]];

plotpoints = 200;

fulltable = Union[Flatten[table2b]]

ContourPlot[fulltable, {p, -1, 15}, {q, -100, 100}, 
 PlotPoints -> plotpoints, PlotRange -> All, Axes -> True]

This gives me an empty box. However, when I plug in directly the evaluated version of fulltable, everything plots correctly. The evaluated fulltable is below.

{-4 + p - q == 
  1 + (1. (p - q))/q - 0.464159 (q/(p - q))^(1/3), -2 + p - q == 
  1 + (1. (p - q))/q - 0.464159 (q/(p - q))^(1/3), 
 p - q == 1 + (1. (p - q))/q - 0.464159 (q/(p - q))^(1/3), 
 2 + p - q == 1 + (1. (p - q))/q - 0.464159 (q/(p - q))^(1/3), 
 4 + p - q == 1 + (1. (p - q))/q - 0.464159 (q/(p - q))^(1/3)}
$\endgroup$
  • $\begingroup$ You haven't included the definition of eq2 (please, do so), but I note that you use a capital P in the Table, whereas you use a lowercase p in the plot. Mathematica is case sensitive... BTW All those evaluates shouldn't be necessary (generally). $\endgroup$ – Sjoerd C. de Vries May 31 '15 at 21:27
  • $\begingroup$ Try using CubeRoot or Surd instead of ^(1/3). The one-third power may be giving you complex values. $\endgroup$ – LouisB May 31 '17 at 9:05
1
$\begingroup$

I'm somewhat sure that this issue depends on the Mathematica version you are using. What you have to understand is that ContourPlot has the attribute HoldAll which indicates that arguments like your fulltable are not evaluated to the list of equations it contains.

Since this leads to empty plots which give new users a hard time, I guess Wolfram included some more sophisticated tests in newer versions of Mathematica to see whether users provided a variable that contains the list of equations.

The conclusion is that the following code works fine in V10, but does show an empty plot in V8.

expr = {Cos[x] + Cos[y] == 1/2};
ContourPlot[expr, {x, 0, 4 Pi}, {y, 0, 4 Pi}]

To make it work in V8, please wrap an Evaluate around expr in the contour plot. This should solve the issue with your real problem too then.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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