I'm studying the effects of some parameter on a complex system. When we change the parameter, the system is converted and we need to write each new state to the list.
Problems encountered in using Manipulate[] for this purpose.
I've created a very simple model to explain: $$x_{n+1}=x_n^p$$ Unfortunately the following program enters into infinite recursion (Do not run this code!)

 newvar = var^p;
 AppendTo[trace, newvar];
 var = newvar,
 {{p, 0.5}, 0.1, 1., 0.1},
 Initialization :> {var = 0.5, trace = {}}]

I understand what's wrong, but I don't know how to get needed result.
Do or Table cannot be used, it must be interactive demonstration with manual change of parameter and recording of results.

  • $\begingroup$ I am not sure I understand your update. Why do you complicate with q? If you want a button to clean the list, just use Button and show it inside Manipulate: Manipulate[...; Row[{Button["Clean trace", trace = {}], var}, ...]. $\endgroup$
    – Domen
    Mar 27 at 15:34
  • $\begingroup$ But this cleaning should be simultaneously with q changing! $\endgroup$
    – lesobrod
    Mar 27 at 15:46
  • $\begingroup$ Why avoid creating a new question? Seems better than having it closed for the Needs more focus reason ("This question currently includes multiple questions in one...."). $\endgroup$
    – Michael E2
    Mar 27 at 15:47

1 Answer 1


You should manually let Mathematica know that it should only track changes of symbol p. Otherwise, it will also track changes of var, and it will keep reevaluating the body of Manipulate indefinitely ...

Manipulate[newvar = var^p;
 AppendTo[trace, newvar];
 var = newvar, {{p, 0.5}, 0.1, 1., 0.1}, 
 Initialization :> {var = 0.5, trace = {}}, TrackedSymbols :> {p}]
  • $\begingroup$ AHA! I assumed that TrackedSymbols was only used for manipulator values, but now I realized that by default all variables inside are involved. Thank you!! $\endgroup$
    – lesobrod
    Mar 27 at 10:46
  • $\begingroup$ @lesobrod, not necessarily all of them, just those that somehow effect the result :) You can read this answer about a similar issue. $\endgroup$
    – Domen
    Mar 27 at 10:53
  • $\begingroup$ @ Domen Please note an additional question! $\endgroup$
    – lesobrod
    Mar 27 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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