Re: random walk visualization

*To*: mathgroup at smc.vnet.net*Subject*: [mg105264] Re: random walk visualization*From*: dh <dh at metrohm.com>*Date*: Wed, 25 Nov 2009 22:59:52 -0500 (EST)*References*: <heimn8$5mc$1@smc.vnet.net>

Alexei Boulbitch wrote: > Dear Community, > > I am making a demonstration for a lecture on random walk. This should > show the random walk evolving in 2D. The following works nicely: > > x := 0; > y := 0; > tab = Table[{x += RandomInteger[{-1, 1}], > y += RandomInteger[{-1, 1}]}, {1000}]; > imTab = Table[ > Show[{Graphics[{Blue, Line[tab[[1 ;; i]]]}], > Graphics[{Red, Thick, Arrowheads[0.03], > Arrow[{tab[[1]], tab[[i]]}]}]}, > PlotRange -> {{-40, 40}, {-40, 40}}], {i, 2, 1000} > ]; > ListAnimate[imTab] > > It however, takes a lot of memory, and few minutes to generate the > graphics list. That is too long. > > If I could directly Animate the graphics instead of generating initially > a graphics list, it would be much faster. This intends to do such a > direct animation: > > x := 0; > y := 0; > tab = Table[{x += RandomInteger[{-1, 1}], > y += RandomInteger[{-1, 1}]}, {1000}]; > Animate[Show[{Graphics[{Blue, Line[tab[[1 ;; i]]]}], > Graphics[{Red, Thick, Arrowheads[0.03], > Arrow[{tab[[1]], tab[[i]]}]}]}, > PlotRange -> {{-40, 40}, {-40, 40}}], {i, 2, 1000} > ] > > But it does not work. I cannot understand the reason. Any idea? > > Regards, Alexei > Hi Alexei, you need to tell "Animate" taht i should change in steps of 1: Animate[Show[{Graphics[{Blue, Line[tab[[1 ;; i]]]}], Graphics[{Red, Thick, Arrowheads[0.03], Print[i]; Arrow[{tab[[1]], tab[[i]]}]}]}, PlotRange -> {{-40, 40}, {-40, 40}}], {i, 2, 1000, 1}] Daniel