0
$\begingroup$

I want to draw curves with manipulation. When I use the following code, I receive nothing.

a = Table[
   E^(-(\[Pi]^2/
     2) (delta^2 Q^4 + 2 q0^2 (Q^3 - defocus Q)^2)), {defocus, 1, 4, 
    1}];
Manipulate[
 Plot[Evaluate[a], {Q, 0, 3}], {{q0, .05}, {.05, .1}}, {{delta, 
   0.1}, {0.1, 0.2}}]

But if I write explicitly the variable "a", I do receive what I need.

I've check the attributes of Manipulate, which has HoldAll. I don't know if it's related to this.

Could you please explain to me why it's like this ? Thanks a lot in advance.

$\endgroup$

marked as duplicate by MarcoB, user9660, m_goldberg, Sjoerd C. de Vries, Yves Klett Feb 16 '16 at 6:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Manipulate needs to "see" the parameters in the definition of a explicitly in order to be able to change them; move the definition of a inside the Manipulate: Manipulate[a=(*your code*); Plot[(*your code*)],...]. $\endgroup$ – MarcoB Feb 15 '16 at 17:54
  • $\begingroup$ See also the docs of Manipulate, in the "Possible Issues" section: "Manipulate only "notices" explicit visible parameters". $\endgroup$ – MarcoB Feb 15 '16 at 17:57
3
$\begingroup$

It is a scoping issue. Make the arguments to a explicit.

Clear[a]

a[Q_, q0_, delta_] =
  Table[
   E^(-(π^2/2) (delta^2 Q^4 + 2 q0^2 (Q^3 - defocus Q)^2)),
   {defocus, 1, 4, 1}];

Manipulate[
 Plot[
  Evaluate[a[Q, q0, delta]],
  {Q, 0, 3},
  PlotLegends -> Automatic],
 {{q0, .05}, {.05, .1}},
 {{delta, .1}, {.1, .2}}]

enter image description here

$\endgroup$

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