Message Boards Message Boards

GROUPS:

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

Posted 11 months ago
871 Views
|
2 Replies
|
2 Total Likes
|

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}]
2 Replies

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 11 months ago

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract