import numpy as np
def random_walk(N):
"""
This function returns the trajectory of an N step random walk on a one dimensional lattice
"""
a = 1 # lattice spacing
x0 = 0
[insert]
return traj
import numpy as np
def random_walk(N):
"""
This function returns the trajectory of an N step random walk on a one dimensional lattice
"""
a = 1 # lattice spacing
x0 = 0
traj = np.zeros(N)
for i in range(N):
traj[i] = x0
x0 += a*(2*np.random.randint(2)-1)
return traj
Go to Google Form