Question
Please Code in python Code for b) import numpy as np import pylab import random # defining the number of steps M = 1000 #creating
Please Code in python
Code for b)
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
pylab.title("Random Walk ($n = " + str(M) + "$ steps)") pylab.plot(x,y) pylab.savefig("rand_walk"+str(M)+".png",bbox_inches="tight",dpi=600) pylab.show()
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 for M-1000 walkers who a 1000 steps. a) b) c) What is the qualitative nature of the distribution of walkers at the end of the simulation? Use a plotting program to draw maps of several independent random walks and discuss. Compute the mean displacement vector by ensemble averaging XN and over the M random walks, for different values of N. Plot as a function of N. d) Compute the mean square displacement by ensemble averaging Rv 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. e) From the log-log plot, what does the functional relationship between N and Ry appear to be? DiscussStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started