import matplotlib.pyplot as plt import numpy as np import random def program1(Nx,Ny, Niters = 100): (x,y) = ( int(Nx/2), int(Ny/2) ) # start in the middle of the box plt.xlim(0,Nx-1) plt.ylim(0,Ny-1) for i in range(Niters): r = random.randint(0,3) if r == 0: x = (x+1)%Nx elif r == 1: x = (x+Nx-1)%Nx elif r == 2: y = (y+1)%Ny elif r == 3: y = (y+Ny-1)%Ny plt.plot(x,y,'ro') # plot the point... plt.pause(0.005) # wait so we can see the point... plt.plot(x,y,'wo') # erase the point The python coding above is a random walk simulator of a particle in 2 dimension. Modifying the simulator to handle N particles instead of one particle. Then, initializing the particles’ positions randomly. After that, extending the random walk simulator so that if two particles are next to each other, they will both freeze, and stop moving. If one of the remaining moving particles winds up next to one of the frozen particles, it should also freeze in place and stop moving.
import matplotlib.pyplot as plt
import numpy as np
import random
def program1(Nx,Ny, Niters = 100):
(x,y) = ( int(Nx/2), int(Ny/2) ) # start in the middle of the box
plt.xlim(0,Nx-1)
plt.ylim(0,Ny-1)
for i in range(Niters):
r = random.randint(0,3)
if r == 0:
x = (x+1)%Nx
elif r == 1:
x = (x+Nx-1)%Nx
elif r == 2:
y = (y+1)%Ny
elif r == 3:
y = (y+Ny-1)%Ny
plt.plot(x,y,'ro') # plot the point...
plt.pause(0.005) # wait so we can see the point...
plt.plot(x,y,'wo') # erase the point
The python coding above is a random walk simulator of a particle in 2 dimension. Modifying the simulator to handle N particles instead of one particle. Then, initializing the particles’ positions randomly. After that, extending the random walk simulator so that if two particles are next to each other, they will both freeze, and stop moving. If one of the remaining moving particles winds up next to one of the frozen particles, it should also freeze in place and stop moving.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps