I am looking to make a nice demo of the problem I mentioned in Integration in Mathematica but it is very slow yet and the Manipulate is not smooth at all.
Considering the below, is there means by which I could improve the situation. That is see a more continuous dynamic. Also I can't get to have the Manipulator open using
Control->Manipulator[Appearance->Open]
arrows = ParallelTable[{
RandomVariate[NormalDistribution[0, Sqrt[1]]],
RandomVariate[NormalDistribution[0, Sqrt[1]]]}, {20000}];
Manipulate[
Graphics[{
White, Rectangle[{-5, -5}, {5, 5}],
Red, Disk[{0, 0}, 1],
Black, Point /@ (arrows[[;; i]]),
Text[Style[
Total[
If[# < 1, 1, 0] & /@
(EuclideanDistance[{0, 0}, #] & /@
arrows[[;; i]])]/Length@arrows[[;; i]] // N,
Bold, 18, "Helvetica"], {-4.5, 4.5}]},
ImageSize -> 800],
{i, Range[2, 20000, 1]},
ControlType -> Manipulator,
SaveDefinitions -> True]
The primary reason for the slowness is because you're calculating the
EuclideanDistance
of all the points till stepi
for every stepi
. You'll see a difference if you take this step out of theManipulate
.Heike's solution is much smoother than yours or Nasser's so I'll use that as an example. You'd use the pre-calculated value of
prob
in it as:I've set the precision uniformly to 4 digits, because otherwise, you'll see the figure jump around when the number of significant digits changes.
See if this is any better for you:
Maybe something like this