The code sample:
Manipulate[
e = RandomVariate[NormalDistribution[0, sigma], n];
{a, e},
{{n, 3}, 1, 5, 1, Appearance -> "Labeled"},
{{sigma, 1}, 1, 2, Appearance -> "Labeled"},
{{a, 0}, 0, 10, 1, Appearance -> "Labeled"}
]
The problem: how to make a to change without updating e given n
and sigma unchanged.
Difference with suggested solutions: random vars depend on other controls (i.e. n and sigma) of Manipulate body.
Answer
Body of Manipulate is wrapped by Dynamic and Dynamic doesn't know what's inside inner Dynamics, that's how we can screen a variable to not prompt the very outer Dynamic to evaluate:
Manipulate[
e = RandomVariate[NormalDistribution[0, sigma], n];
{Dynamic@a, e},
{{n, 3}, 1, 5, 1, Appearance -> "Labeled"},
{{sigma, 1}, 1, 2, Appearance -> "Labeled"},
{{a, 0}, 0, 10, 1, Appearance -> "Labeled"}
]
Comments
Post a Comment