mercredi 30 janvier 2019

2D Square Lattice Random Walker Problem Mean Displacement Vectors

The Question is asking to compute the mean displacement vector by ensemble averaging xN and yN over the M random walks, for different values of N. Plot as a function of N and then the mean squre displacement by ensemble averaging R_N^2 for M-1000 walkers who are all originally at the origin in two-d.

Here is my coder to put the maps of serval independent random walks:

import numpy as np
import pylab 
import random 

# defining the number of steps 
M = 1000

#creating two array for containing x and y coordinate 
#of size equals to the number of size and filled up with 0's 
x = np.zeros(M) 
y = np.zeros(M) 

# filling the coordinates with random variables

for i in range(1, M):
      value = random.randint(1, 4)
      if value == 1:
           x[i] = x[i - 1] + 1
           y[i] = y[i - 1] 
      elif value == 2: 
           x[i] = x[i - 1] - 1
           y[i] = y[i - 1] 
      elif value == 3: 
           x[i] = x[i - 1] 
           y[i] = y[i - 1] + 1
      else: 
           x[i] = x[i - 1] 
           y[i] = y[i - 1] - 1


def compute_SquareMean(value):
   totalsize=len(value)
   msd=[]
  for i in range(totalsize-1):
      j=i+1
      msd.append(np.sum((value[0:-j]      

value[j::])**2)/float(totalsize-j)) msd=np.array(msd) return msd

print(compute_SquareMean)
pylab.title("Random Walk ($n = " + str(M) + "$ steps)") 
pylab.plot(x,y)      
pylab.show() 

Can someone show me the code to compute the mean displacement vector by ensemble averaging xN and yN over the M random walks, for different values of N and the mean squre displacement by ensemble averaging R_N^2. I suspect my compute_SquareMean function is not working properly because it is giving a location as the output. It should be noted that the for loop for the random walker path is working perfectly. Thank you




Aucun commentaire:

Enregistrer un commentaire