How to Compile this code (multiple random walks)
- To: mathgroup at smc.vnet.net
- Subject: [mg118068] How to Compile this code (multiple random walks)
- From: "mfific at gmail.com" <mfific at gmail.com>
- Date: Mon, 11 Apr 2011 07:06:56 -0400 (EDT)
Hi All,
I would appreciate help with Compile function. Below is the code that
I could not compiled. The output are the three random walk counters
with (-5, 5) bounds, along with a counter for a number of steps. The
compile does not work here, I assume because the output is a matrix
(it works if there is only one counter). But I need these three
counters running in parallel for later development. Any help would be
appreciated.
thanks,
Mario Fific
Transpose[{Range[0, Length[#] - 1], #}] &@
NestWhileList[(# + {If[Random[] > .5, 1, -1],
If[Random[] > .5, 1, -1], If[Random[] > .5, 1, -1]}
) &, {0, 0, 0}, -5 < #[[1]] < 5 && -5 < #[[2]] < 5 && -5 < #[[3]]
< 5 & ]