I have created an application that simulates a random sample for the experiment of rolling a dice three times and recording the outputs as $(a,b,c)$. The code is the following

DynamicModule[{a = 100},
    Row[{Style["Ingrese el tamaño de la muestra ", Italic, 14], 
      InputField[Dynamic[a], Number, FieldSize -> 10]}],
     \[Mu] = 
      Mean[N[Mean /@ 
          DiscreteUniformDistribution[{1, 6}], {a, 
           3}]]](*media de los datos*);
     \[Sigma] = 
       N[Mean /@ 
          DiscreteUniformDistribution[{1, 6}], {a, 
           3}]]](*desviacion estandar de los datos*);
      Histogram[{Mean /@ 
          DiscreteUniformDistribution[{1, 6}], {a, 3}]}, {0.5, 7, 
        0.34}, "PDF",
       ImageSize -> Large,
       PlotLabel -> "media: " <> ToString[\[Mu]],
       AxesLabel -> {None, Style["Frecuencia", Italic]},
       ChartStyle -> Gray],
      Plot[PDF[NormalDistribution[\[Mu], \[Sigma]], x], {x, 0, 7}, 
       PlotStyle -> Red]]

enter image description here

The problem arises when I localized the variables [mu] and [sigma] in the DynamicModule, because the program lags and the output change all the time. I don't know why this happened, or what is the error in my code.

| improve this question | | | | |
  • 1
    $\begingroup$ You may add TrackedSymbols :> {a} to Dynamic so that only change in a will trigger update in output, in that case μ and σ can be localized. $\endgroup$ – Alx Feb 14 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.