I made a Manipulate box that is working very well, using lots of random numbers. I would like to add a button to "reset" (i.e. to change, randomize, or reselect) all the random parameters.
Here's the code I added to the Manipulate box, but it doesn't work :
Row[{Spacer[200],
Button[
"Randomize all parameters",
Clear["alpha", "Phase", "Amplitude", "Frequency"],
Appearance -> "Palette",
ImageSize -> {150, 28}
]
}],
What should I use instead of Clear["alpha", "Phase", "Amplitude", "Frequency"] to randomize all these parameters, according to their definitions ?
EDIT : Here's a complete MWE showing the problem :
Clear["Global`*"]
Amplitude[k_] := Amplitude[k] = RandomReal[{0.5, 1.5}]
Frequency[k_] := Frequency[k] = RandomReal[{1, 5}]
Phase[k_] := Phase[k] = RandomReal[{0, 2Pi}]
Manipulate[
Plot[
Sum[Amplitude[k]Sin[2Pi Frequency[k]t + Phase[k]],
{k, 1, Nwaves}
],
{t, 0, 1},
Frame -> True,
PlotRange -> {{0, 1}, {-5, 5}},
PerformanceGoal -> "Quality",
ImageSize -> 600
],
{{Nwaves, 1, Style["Number of waves", 10]}, 1, 20, 1, Appearance -> "Labeled"},
Delimiter,
Row[{
Button[
"Reset random parameters",
{(* Reset command for "Amplitude", "Frequency", "Phase" *)},
Appearance -> "Palette",
ImageSize -> {250, 28}
]
}],
ControlPlacement -> Bottom
]
EDIT 2 : The "duplicate" referenced above doesn't apply to this question, since the answers are specific to that question. I don't see how to apply them to the question here.
DownValues. Something like,DownValues[alpha] = DownValues[alpha][[{-1}]], which resets the rules associated withalphato only the original definition. Without an idea of what's happening inside theManipulate, that's the best I can say right now. – march Mar 25 '16 at 15:24DownValuesof a function (i.e. clear some parts of a memo-ized function), and perhaps a combination of those two posts would compose a duplicate. However, since two posts would be required, perhaps it's not a dupe. Nonetheless, those are two good posts to reference. – march Mar 25 '16 at 16:09Manipulate. – garej Mar 25 '16 at 17:31Cleareverything command, and introduce my functions before theManipulatecode. I don't know if this a good practice (probably not !). If I open several Manipulate projects, I can use just one at a time and need to recompile the code to use another one. So I guess my habits aren't very good. – Cham Mar 25 '16 at 17:46