Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: random walk visualization

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105291] Re: [mg105258] Re: random walk visualization
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 26 Nov 2009 06:14:18 -0500 (EST)
  • References: <heimn8$5mc$1@smc.vnet.net> <200911251121.GAA13749@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

That "walks" off the PlotRange on some runs and compresses the path too  
much on others, so I'd suggest:

pt = {0, 0};
tbl = Table[pt += RandomInteger[{-1, 1}, 2], {1000}];
limits = {Min@#, Max@#} & /@ Transpose@tbl;
Animate[
  Show[{Graphics[{Blue, Line[tbl[[1 ;; i]]]}],
    Graphics[{Red, Thick, Arrowheads[0.03],
      Arrow[{tbl[[1]], tbl[[i]]}]}]}, PlotRange -> limits], {i, 2,
   1000, 1}]

Here's another approach, too:

limit = 10^6;
pts = {pt = pt1 = {0, 0}};
Animate[
  Show[{Graphics[{Blue,
      Line[AppendTo[pts, pt += RandomInteger[{-1, 1}, 2]]]}],
    Graphics[{Red, Thick, Arrowheads[0.03], Arrow[{pt1, pt}]}]},
   PlotRange -> 50 {{-1, 1}, {-1, 1}}], {i, 2, limit, 1},
  AnimationRepetitions -> 1]

That one can also walk off the chart, and AppendTo gets slow, but it's  
still interesting.

Bobby

On Wed, 25 Nov 2009 05:21:21 -0600, Norbert Marxer <marxer at mec.li> wrote:

> On Nov 25, 8:35 am, Alexei Boulbitch <Alexei.Boulbi... at iee.lu> 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
>>
>> --
>> Alexei Boulbitch, Dr., habil.
>> Senior Scientist
>>
>> IEE S.A.
>> ZAE Weiergewan
>> 11, rue Edmond Reuter
>> L-5326 Contern
>> Luxembourg
>>
>> Phone: +352 2454 2566
>> Fax:   +352 2454 3566
>>
>> Website:www.iee.lu
>>
>> This e-mail may contain trade secrets or privileged, undisclosed or  
>> otherwise confidential information. If you are not the intended  
>> recipient and have received this e-mail in error, you are hereby  
>> notified that any review, copying or distribution of it is strictly  
>> prohibited. Please inform us immediately and destroy the original  
>> transmittal from your system. Thank you for your co-operation.
>
> Hello
>
> All you have to do is to include a step size in Animate: i.e.  {i, 2,
> 1000, 1}
>
> This works.
>
> 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,1}
>  ]
>
> Best Regards
> Norbert Marxer
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: computing expectations for probability distributions in mathematica
  • Next by Date: How to make {f,g}[a,b,c] to become {{f[a],g[a]},{f[b],g[b]},{f[c],g[c]}}
  • Previous by thread: Re: random walk visualization
  • Next by thread: Re: random walk visualization