I learnt about Temporal motivation theory from my friend. So I tried to plot something like this:

    {n, 1, 10}, 
    Dynamic[With[{t = n}, 
        Plot[(ε V)/(1 + Γ D), {D, 0, t}], 
      {V, 0, 5}, 
      {Γ, 0, 1}, 
      {ε, 0, 5}]]]

Whenever n is changed, the inner Manipulate's sliders get reset. How can I keep this from happening?

enter image description here

  • $\begingroup$ why all this complication for? Why not just use Manipulate as normally it is meant to be used? What is wrong with Manipulate[ Plot[(\[CurlyEpsilon] V)/(1 + \[CapitalGamma] D), {D, 0, n}], {V, 0, 5}, {\[CapitalGamma], 0, 1}, {\[CurlyEpsilon], 0, 5}, {n, 1, 10} ] $\endgroup$ – Nasser Jul 3 '17 at 16:43

Every time you change n, the inner Manipulate expression gets re-evaluated, so of course all its variables, which in this case are all controls, get reinitialized. The way to fix it is to get rid of the nesting and have only one Manipulate expression, You don't need the outer DynamicModule either (a Manipulate expression is transformed into a dynamic module when it is evaluated, so your code produces three nested levels of dynamic modules.)

So what you need is much simpler than what you wrote.

  Plot[(ε V)/(1 + Γ D), {D, 0, n}],
  {{n, 5}, 1, 10, 1, Appearance -> "Labeled"},
  {{V, 2}, 0, 5, Appearance -> "Labeled"},
  {{Γ, .5}, 0, 1, Appearance -> "Labeled"},
  {{ε, 1}, 0, 5, Appearance -> "Labeled"}]



  • Instead of having n displayed in a panel, I use the option Appearance to display its value on the right-hand side of its slider. I do the same for the other controls because I think it is almost always good make the current value of the controls visible.
  • Presuming that n is meant to represent an integer variable, I have constrained its slider to step by 1.
  • I have added explicit initialization to all the controls.

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.