You are on page 1of 5

1. (contd.

For 100,000 steps :


For 100 persons, 1000 steps each :
import numpy
import random
import matplotlib.pyplot as plt

n = int(input("Enter the no. of steps : "))


m = int(input("Enter the no. of different walkers: "))
x = numpy.zeros(n)
y = numpy.zeros(n)
t = numpy.zeros(n)
delta1 = numpy.zeros(n)
def Average(delta1):
return sum(delta1) / len(delta1)

for j in range(1,m):
for i in range(1,n):
walk = random.randint(1,4)
if walk == 1:
x[i] = x[i-1] + 1
y[i] = y[i-1]
t[i] = t[i-1] + 1
delta1[i] = (x[i]**2) + (y[i]**2)
elif walk == 2:
x[i] = x[i-1] - 1
y[i] = y[i-1]
t[i] = t[i-1] + 1
delta1[i] = (x[i]**2) + (y[i]**2)
elif walk == 3:
x[i] = x[i-1]
y[i] = y[i-1] + 1
t[i] = t[i-1] + 1
delta1[i] = (x[i]**2) + (y[i]**2)
else:
x[i] = x[i-1]
y[i] = y[i-1] - 1
t[i] = t[i-1] + 1
delta1[i] = (x[i]**2) + (y[i]**2)

delta2 = Average(delta1)

plt.plot (t, x, color= 'blue')


plt.xlabel('time')
plt.ylabel('distance in x direction')
plt.show()

plt.plot (t, y, color= 'green')


plt.xlabel('time')
plt.ylabel('distance in y direction')
plt.show()

plt.plot (x, y, color= 'yellow')


plt.xlabel('distance in x direction')
plt.ylabel('distance in y direction')
plt.show()

plt.plot (delta2, t, color= 'red')


plt.xlabel('time')
plt.ylabel('average of mean square distance')
plt.show()

OUTPUT:

Enter the no. of steps : 1000

Enter the no. of different walkers: 100

You might also like