I wrote the following code
ClearAll["Global`*"]
simulateRandomWalk[steps_Integer, prob_] :=
Module[{accumulatedSteps, plotRange},
accumulatedSteps =
Prepend[Accumulate[
RandomChoice[{N[1 - prob], N[prob]} -> {-1, 1}, steps]], 0];
plotRange = {{0, steps}, {Min[accumulatedSteps] - 1,
Max[accumulatedSteps] + 1}};
Animate[
ListLinePlot[{Range[0, n], Take[accumulatedSteps, n + 1]} //
Transpose,
PlotRange -> plotRange], {n, Range[0, steps],
AnimationRepetitions -> 1}
]
];
simulateRandomWalk[100, 0.5]
to simulate a random walk with $n$ steps and a probability $p$ of going up (and $1 - p$ for going down). However, it appears that ListLinePlot
gives me some warnings/error that go away almost immediately, so I cannot see them well, let alone deal with them. Any ideas as to what I should do?
Module
withDynamicModule
. This doesn't answer how to diagnose errors, it's simply a suggestion based on experience. :-) $\endgroup$ – Mr.Wizard Mar 21 '15 at 10:39DynamicModule
is indeed what was causing the problems! $\endgroup$ – d125q Mar 21 '15 at 11:45