# How to separate the performance of controls in Manipulate?

I would like to build a Manipulate object, for which some variables will be related to corresponding controls. For example, in this simple Manipulate object, if I change any slider control, both variables mu1 and mu2 are recalculated

Manipulate[
S1 = RandomVariate[NormalDistribution[mu1, 1], 10];
S2 = RandomVariate[NormalDistribution[mu2, 1], 10];
TableForm[{S1, S2}],  {mu1, -1, 1}, {mu2, -1, 1}]


Is it possible to establish recalculation for each variable separately: when the 1st control is changed, only mu1 is recalculated; when 2nd--- only mu2?

Make s1 and s2 manipulate parameters with no controls and update them using TrackingFunction in controls mu1 and mu2:

Manipulate[Style[#, 16] & @ TableForm[{s1, s2}],
{mu1, -1, 1, TrackingFunction -> (mu1 = #;
s1 = RandomVariate[NormalDistribution[#, 1], 5]; &)},
{mu2, -1, 1, TrackingFunction -> (mu2 = #;
s2 = RandomVariate[NormalDistribution[#, 1], 5]; &)},
{{s1, RandomVariate[NormalDistribution[-1, 1], 5]}, None},
{{s2, RandomVariate[NormalDistribution[-1, 1], 5] }, None}]


• Yours works a lot better than mine does, this is definitely the correct solution to the question. Dec 22, 2020 at 14:13

By using Dynamic[] we are able to localise variables, preventing the entire expression from updating.

Clear[S1];
Clear[S2];

S1[mu1_] := RandomVariate[NormalDistribution[mu1, 1], 1][[1]];
S2[mu2_] := RandomVariate[NormalDistribution[mu2, 1], 1][[1]];

Manipulate[
{
{{Table[Dynamic[S1[mu1]], 10]}},
{{Table[Dynamic[S2[mu2]], 10]}}
} // TableForm,
{mu1, 0, 1},
{mu2, 0, 1}
]


I see that you have been asking this question for over a year now on various forums, I hope that I helped you today.

• In addition, it's also usually good practise to use the TrackedSymbols option of Dynamic to specify more precisely when each display element should update. Dec 21, 2020 at 16:23
• I hope you helped, but I don't remember about asking this question anywhere Dec 21, 2020 at 16:39
• @Konstantin you asked on Wolfram Community 1 year ago community.wolfram.com/groups/-/m/t/1809181 Dec 21, 2020 at 17:06
• Oh, sorry, I forgot this question on Wolfram Community :(( Dec 22, 2020 at 17:46