## A for good and evil as well as loopless
## total displacement function of random walk
## that takes in the step numbers as an
## argument and returns the displacement
## of the rnd walker.Note that the probabilities
## to turn rigth and left are equal but the left
## step is twice the rigth step.
## Usage : rw_uneven(N)
function rw_uneven(N)
rn=rand(N,1); ## If the element of a random vector
r=-(rn<0.5); ## is smaller than 0.5, then return -1,
li=find(r == 0); ## Else return 2(equal probability).
r(li)=2;
x=sum(r) ## total displacement
endfunction
Comments
Post a Comment