Message Boards Message Boards

0
|
3159 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

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

Posted 6 years ago

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
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 BY: Neil Singer
Posted 6 years ago

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

POSTED BY: Daniel Huber
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