Message Boards Message Boards

[✓] Stop re-evaluating an assignment like x=x+1 in Manipulate?

GROUPS:

Can some shed some light on the following behaviour of manipulate:

This works like expected:

Manipulate[
 x = x0;
 x
 , {x0, 0, 1}]

However, if there is an assignment like x= x+1, where the same variable is on both side of the "=", this seems to be interpreted as a recursion and Manipulate does not stop evaluating:

Manipulate[
x = x0;
x = x + 1;
x
, {x0, 0, 1}]
POSTED BY: Daniel Huber
Answer
12 days ago

Daniel,

I assume by "recursion" you mean that the Manipulate keeps reevaluating and getting the same answer (not counting up).

Manipulate[x = x0;
 x = x + 1;
 x, {x0, 0, 1}, TrackedSymbols :> {x0}]

Will fix your issue. Now it only updates when x0 changes and not when x changes (which causes a total reevaluation of the expressions)

Regards,

Neil

POSTED BY: Neil Singer
Answer
12 days ago

Tank's a lot, there is always something I did not know about Mathematica.

POSTED BY: Daniel Huber
Answer
12 days ago

Group Abstract Group Abstract