Question: *Only do X_N and Y_N and R_N^2 part* In Python *code for first part is:* def step(x,y,i): direction = rn.randint(1,4) if direction==1: x[i]=x[i-1]+1 y[i]=y[i-1] elif

 *Only do X_N and Y_N and R_N^2 part* In Python *code

for first part is:* def step(x,y,i): direction = rn.randint(1,4) if direction==1: x[i]=x[i-1]+1

*Only do X_N and Y_N and R_N^2 part*

In Python

*code for first part is:*

def step(x,y,i): direction = rn.randint(1,4) if direction==1: x[i]=x[i-1]+1 y[i]=y[i-1] elif direction==2: x[i]=x[i-1]-1 y[i]=y[i-1] elif direction==3: x[i]=x[i-1] y[i]=y[i-1]+1 elif direction==4: x[i]=x[i-1] y[i]=y[i-1]-1 else: pass def graphit(x,y,n): plt.title("Random {0} Walk Last Location {1},{2}".format(n,int(x[n-1]),int(y[n-1])) ) plt.plot(x,y) plt.plot([x[1],x[1]],[y[1]-10,y[1]+10], "b-") plt.plot([x[1]-10,x[1]+10],[y[1],y[1]], "b-") plt.plot([x[n-1]-10,x[n-1]+10],[y[n-1],y[n-1]], "r-") plt.plot([x[n-1],x[n-1]],[y[n-1]-10,y[n-1]+10], "r-") plt.savefig("rand_walk"+str(n)+".png",bbox_inches="tight",dpi=600) plt.show() #10 is number of figures for k in range(10): n=100000#int(input("Number of steps:")) x=np.zeros(n) y=np.zeros(n) for i in range(1,n): step(x,y,i) graphit(x,y,n)

Write a program that performs M random walks of N steps in two dimensions on a square lattice, assuming that each step is chosen at random, and each of the four possible directions are equally probable Run the program for M-1000 walkers who are all originally at the origin. Allow the walkers to take at least 1000 steps Compute the mean displacement vector by ensemble averaging x and y over the M random walks, for different values of N. Plot as a function of N. Compute the mean square displacement by ensemble averaging Ry over the M random walks, for different values of N. Plot as a function of N on a linear-linear plot, and a log-log plot

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!