RE: Re: Plot Random Walk!
- To: mathgroup at smc.vnet.net
- Subject: [mg34419] RE: [mg34414] Re: Plot Random Walk!
- From: "DrBob" <majort at cox-internet.com>
- Date: Sun, 19 May 2002 04:14:33 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Instanton's solution has a couple of interesting features. One is that the PlotRange changes randomly from one chart to the next, which makes it difficult to watch the animation. Another is that 100 random walk plots actually ends up being 101, with the last plot being a combination of the first 100 random walks on a single plot. That too makes for a strange animation; we might not want that 101st plot, or we might want it all by itself as a static plot. I set out to achieve more control over all this. plotTable builds a set of random walks (lists, not plots). animatedWalks build the corresponding set of ListPlots, with display inhibited. randomWalk[n_] := NestList[ (# + (-1)^Random[Integer]) &, 0, n]; plotTable[m_Integer] := randomWalk[200] & /@ Range[m] animatedWalks[m_Integer] := Module[{t, lim}, t = plotTable[m]; lim = 5Ceiling[#/5] &[Max @@ Abs /@ Flatten[t]]; ListPlot[#, PlotJoined -> True, PlotRange -> lim{-1, 1}, DisplayFunction -> Identity] & /@ t ] The following builds 10 random walk plots, undisplayed. a = animatedWalks[10, False]; The following displays them all on one chart: Show[a, DisplayFunction -> $DisplayFunction]; The following displays them as an animation --- WITHOUT the final chart that combines them all. Show[#, DisplayFunction -> $DisplayFunction] & /@ a; SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute["OpenCloseGroup"] FrontEndTokenExecute["SelectionAnimate"] Finally, the following animates them the original way, with the aggregate of all the walks coming last in each cycle: Show[#, DisplayFunction -> $DisplayFunction] & /@ a; Show[a, DisplayFunction -> $DisplayFunction]; SelectionMove[EvaluationNotebook[], All, GeneratedCell] FrontEndTokenExecute["OpenCloseGroup"] FrontEndTokenExecute["SelectionAnimate"] Bobby Treat -----Original Message----- From: Instanton [mailto:lzhao at ihw.com.cn] To: mathgroup at smc.vnet.net Subject: [mg34419] [mg34414] Re: Plot Random Walk! First, corrections to your code for the definition of RandomWalk: RandomWalk[n_] := NestList[(# + (-1)^Random[Integer]) &, 0, n]; Then, define a table of ListPlots: plottable[m_]:=Table[ListPlot[RandomWalk[200], PlotJoined -> True],{i,1,m}]; Last, Show the plots: Show[plottable[100]] Good luck. Instanton "Andrea" <cigen at hil.de> wrote in message news:<ac2nmv$3s4$1 at smc.vnet.net>... > With this procedure i plot a randomwalk > > RandomWalk[n_]:=NetList[#+(-1)^Random[Integer ])&,0,n] > > ListPlot [RandomWalk[200],PlotJoined-->True] > > > > How can i plot for example 100 random walk on the same plot?? > > Thankyou