4
$\begingroup$

I would like to plot a function which involves multiple symbols created using Unique. Consider the following simple example.

X = {Unique["x"]}
Plot[Evaluate[2 X[[1]]], {Evaluate[X[[1]]], 0, 1}]

Unfortunately, this results in an error Plot::write: "Tag Evaluate in Evaluate[X[[1]]] is Protected.".

Is there a way to plot using "dynamic" variables?

$\endgroup$

closed as off-topic by m_goldberg, bbgodfrey, user9660, Öskå, ubpdqn Feb 8 '16 at 9:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, bbgodfrey, Community, Öskå, ubpdqn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Related, possible duplicate: (7756), (20718), (46751) $\endgroup$ – Mr.Wizard Feb 7 '16 at 14:49
  • $\begingroup$ @Mr.Wizard It seems to me the underlying problem is that Evaluate should be placed outside the list, Evaluate@{X[[1]], 0, 1}. This is the issue in many posts, such as (5235) and (47907), and is also explained in this answer. I couldn't find one in which the issue was specifically using Evaluate in the second argument to Plot. It's usually the first argument. $\endgroup$ – Michael E2 Feb 7 '16 at 17:09
  • $\begingroup$ @MichaelE2 Yes, those are good, perhaps better, originals. And I found another related question and added it to my comment above. This question seems headed toward closure as "in the documentation" at this point; hopefully the links are useful to Markus and others. $\endgroup$ – Mr.Wizard Feb 7 '16 at 17:14
  • $\begingroup$ Thank you very much for the links. $\endgroup$ – Markus Müller Feb 7 '16 at 17:56
8
$\begingroup$

If you have a relatively recent version of Mathematica, you don't need to use Evaluate.

X = {Unique["x"]};
With[{x = X[[1]]}, Plot[Legended[2 x, x], {x, 0, 1}]]

plot

$\endgroup$
  • $\begingroup$ Using X={Unique["x"]};Plot[Legended[2 X[[1]], X[[1]]], {X[[1]], 0, 1}] does not work. I need something that works for symbol lists. $\endgroup$ – Markus Müller Feb 7 '16 at 13:45
  • 1
    $\begingroup$ @MarkusMüller Please edit your question to state clearly what you do need. $\endgroup$ – bbgodfrey Feb 7 '16 at 13:55
  • $\begingroup$ Sorry if my question was not clear. I fixed it. Basically, I am wondering how to plot a function which depends on "dynamic" variables created using Unique. $\endgroup$ – Markus Müller Feb 7 '16 at 14:00
  • $\begingroup$ With solves the problem. Thanks. $\endgroup$ – Markus Müller Feb 7 '16 at 14:02

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