Skip to main content
improve spelling and grammar
Source Link
creidhne
  • 5.8k
  • 6
  • 25
  • 32

How to obtaineobtain desirable performance of dynamicaldynamic variable?

It is neededI need to create the code that generates a sample based on an adjustable parameter and, later, interactively calculates statistics or buildbuilds a plot for the generated sample. Say, let'sLet's insert a slider

Slider[Dynamic[m1], {-2, 2}]

and perform the calculation

(* 1 *) Sample = Dynamic[RandomVariate[NormalDistribution[m1, 0.5], 10]]
(* 2 *) Dynamic[Mean[Sample]]
(* 3 *) Mean[Sample]
(* 4 *) Dynamic[Mean[RandomVariate[NormalDistribution[m1, 0.5], 10]]]

None of 4 items has the required performance. 1: only calculates a sample, 2: returns Mean[{...}] unevaluated for another sample, 3: the same, unevaluated for 3d sample, 4: does calculate Mean for 4th sample.

It's possible to use control for creating static variable (see my question), but now I need dynamical behaviourthe dynamic behavior mentioned above.

How to obtaine desirable performance of dynamical variable?

It is needed to create the code that generates a sample based on an adjustable parameter and, later, interactively calculates statistics or build a plot for generated sample. Say, let's insert a slider

Slider[Dynamic[m1], {-2, 2}]

and perform the calculation

(* 1 *) Sample = Dynamic[RandomVariate[NormalDistribution[m1, 0.5], 10]]
(* 2 *) Dynamic[Mean[Sample]]
(* 3 *) Mean[Sample]
(* 4 *) Dynamic[Mean[RandomVariate[NormalDistribution[m1, 0.5], 10]]]

None of 4 items has required performance. 1: only calculates a sample, 2: returns Mean[{...}] unevaluated for another sample, 3: the same, unevaluated for 3d sample, 4: does calculate Mean for 4th sample.

It's possible to use control for creating static variable (see my question), but now I need dynamical behaviour mentioned above.

How to obtain desirable performance of dynamic variable?

I need to create the code that generates a sample based on an adjustable parameter and, later, interactively calculates statistics or builds a plot for the generated sample. Let's insert a slider

Slider[Dynamic[m1], {-2, 2}]

and perform the calculation

(* 1 *) Sample = Dynamic[RandomVariate[NormalDistribution[m1, 0.5], 10]]
(* 2 *) Dynamic[Mean[Sample]]
(* 3 *) Mean[Sample]
(* 4 *) Dynamic[Mean[RandomVariate[NormalDistribution[m1, 0.5], 10]]]

None of 4 items has the required performance. 1: only calculates a sample, 2: returns Mean[{...}] unevaluated for another sample, 3: the same, unevaluated for 3d sample, 4: does calculate Mean for 4th sample.

It's possible to use control for creating static variable (see my question), but now I need the dynamic behavior mentioned above.

Source Link
Konstantin
  • 926
  • 5
  • 9

How to obtaine desirable performance of dynamical variable?

It is needed to create the code that generates a sample based on an adjustable parameter and, later, interactively calculates statistics or build a plot for generated sample. Say, let's insert a slider

Slider[Dynamic[m1], {-2, 2}]

and perform the calculation

(* 1 *) Sample = Dynamic[RandomVariate[NormalDistribution[m1, 0.5], 10]]
(* 2 *) Dynamic[Mean[Sample]]
(* 3 *) Mean[Sample]
(* 4 *) Dynamic[Mean[RandomVariate[NormalDistribution[m1, 0.5], 10]]]

None of 4 items has required performance. 1: only calculates a sample, 2: returns Mean[{...}] unevaluated for another sample, 3: the same, unevaluated for 3d sample, 4: does calculate Mean for 4th sample.

It's possible to use control for creating static variable (see my question), but now I need dynamical behaviour mentioned above.