# Manipulate executes twice [duplicate]

I need help, guys! Here the script:

numberProcesses = 24;
numberLevels = 4;
Manipulate[
numberExperts = E;
processMatrix =
Table[RandomReal[{0, 1}, WorkingPrecision -> 2], {i, E}, {j,
numberLevels}];
aggregatedMark =
Table[Total[processMatrix[[All, k]]]/E, {k, numberLevels}];
deviation =
Table[N[Sqrt[
Sum[RootApproximant[(processMatrix[[h, g]] -
aggregatedMark[[g]])^2], {h, E}]/E], 2], {g, numberLevels}];
variation =
Table[N[RootApproximant[deviation[[g]]/aggregatedMark[[g]]*100],
2], {g, numberLevels}];
graphTable =
Table[Show[{Histogram[processMatrix[[All, j]], {0, 1, 0.1}, "PDF"],
SmoothHistogram[processMatrix[[All, j]],
PlotStyle -> Thick]}], {j, numberLevels}];
groupMark = {};
k = {};
l = {};
tmax = 2;
t = 1;
AppendTo[k, Table[1/E, {i, E}]];
While[True,
AppendTo[groupMark,
Table[N[Sum[processMatrix[[i, j]]*k[[t, i]], {i, E}], 2], {j,
numberLevels}]];
AppendTo[l,
RootApproximant[
Sum[Sum[groupMark[[t, i]]*processMatrix[[j, i]], {j, E}], {i,
numberLevels}]]];
temp = Table[
N[1/l[[t]]*
Sum[(processMatrix[[i, j]]*groupMark[[t, j]]), {j,
numberLevels}], 2], {i, E - 1}];
AppendTo[k,
AppendTo[temp,
N[RootApproximant[1 - Sum[temp[[i]], {i, E - 1}]], 2]]];
If[t >= tmax,
If[Max[Table[
Abs[groupMark[[t, i]] - groupMark[[t - 1, i]]], {i,
numberLevels}]] <= 0.0001, Break[], t++], t++]];
viewTable = Text[Grid[Append[Append[Append[Append[Append[
MapThread[
Prepend, {Prepend[
processMatrix, {"Второй уровень", "Третий уровень",
"Четвёртый уровень", "Пятый уровень"}],
Prepend[Table[i, {i, E}], ""]}],
Insert[aggregatedMark, "fi",1]],
Insert[deviation, "Sigma", 1]],
Insert[variation, "V", 1]],
Insert[graphTable, "Graph", 1]],
Insert[groupMark[[t, All]], "Mark", 1]], Frame -> All,
Background -> LightYellow]], {{E, 3, "Number"}, 2,
100, 1}, ContinuousAction -> False, TrackedSymbols -> {E}]


It does: And most of that works well, but when the E value is changed Manipulate executes all twice... Why is it so? I really don't understand. I tried delete the graphs from the table. After that I saw Manipulate didn't execute all twice. It's magic =/

Secondly, I don't know how I can get real numbers with only two digits after the point (0.xx). When I use N[,2] Mathematica returns sometimes 0.0xx or 0.00xx. But I wanna get 0.0x or 0.00 (of course, using the standard rule for rounding). How can I do it?

And last but not least, as you can see I used such functions as RootApproximant. I don't want use it, but sometimes without 'em Mathematica says: No significant digits are available to display. What can I do?

I will be happy if someone will help me optimize the script. Thank you for your attention.

EDITED

Manipulate executes all twice. It was solved - Stackoverflow. Thanks, @SjoerdC.deVries.

## 2 Answers

From my StackOverflow answer on a similar question of three years ago:

This can be solved by adding the option PerformanceGoal -> "Quality" to the Plot function.

During the display of manipulated items a lower fidelity sample of the object can be shown depending on the PerformanceGoal setting. A higher fidelity version is drawn at the end of the manipulation, if necessary. It is this later redrawing which seems to be causing the problem here.

• Thanks you for your attention! :) It works well! – Vitaliy Sergeyevich Barash Apr 20 '14 at 20:25
• I figure a correct, accepted answer deserves at least one upvote, even on a duplicate, as sign that someone else agrees with it, per the SE model. (Just happened to run across it this morning. April is my busiest time of the year, in general) – Michael E2 Feb 1 '15 at 13:04
• @MichaelE2 thanks, much tidier this way :) – Sjoerd C. de Vries Feb 1 '15 at 16:28

You know how people on this site are always talking about not using capital letters as symbols because it might cause problems? Well... E is the symbol for the exponential constant (2.718...). The first time through, the Manipulate evaluates everything as if E were Exp, then it goes through again and evaluates E as the variable in your Manipulate, i.e., {E, 3, "Number"}. So just change all the occurrences of E to e (or something else) and the multiple evaluation problem vanishes.

• Thx, I done it, but Manipulate still executes all twice =/ – Vitaliy Sergeyevich Barash Apr 20 '14 at 20:16
• Only executes once on my machine. Given Sjoerd C. de Vries answer, maybe it's the speed of the machines. – bill s Apr 20 '14 at 21:11