Question: l I cant fix this error, I'm using spyder. Also some other help as well with shifting the code that creates the random walk x

 l I cant fix this error, I'm using spyder. Also some

other help as well with shifting the code that creates the randoml

walk x and y position arrays from the main code into a

I cant fix this error, I'm using spyder. Also some other help as well with shifting the code that creates the random walk x and y position arrays from the main code into a function called make_walk(n_timesteps, step_size) in randomwalker.py. This function should accept an integer n_timesteps that indicates the number of steps and a float for the step_size and it should return TWO arrays for n_timesteps x positions and y positions for the random walker and Create a function in randomwalker.py called mag(x, y) which takes the x and y position arrays and computes the distance from the origin at all the timesteps. Do this using array arithmetic so you do it in just one math operation instead of iterating over all the points in the arrays. You will need to use np.sqrt() to compute the square root of all the points in the arrays. Modify your main code to create a new array called dist that is the array of distances computed by mag(). Make a labeled plot of distance versus timestep after plotting the walk itself (remember to call plt.show() after each plot, or else Python will try to over plot the two plots.

from random import random import numpy as np def coord(step_size): a = random if a > .50: z = step_size else: z = -step_size return z q = coord(3) print(q) def make_walk (n_timesteps, step_size): n_timesteps = 10000 step_size = 3 x = np.empty(n_times teps, float) y = np.empty(n_timesteps, float) x[@]= 0 y[0]= 0 for i in range (i, n_timesteps): x[i] = x[i - i] coord(step_size) y[i] = yli - 1] + coord(step_size) return x,y #def mag (x,y): mag = ((np.sqrt( x ** 2),y ** 2)) # print (mag) # import numpy as np import matplotlib.pyplot as plt from randomwalker import coord , make_walk x = make_walk(n_timesteps, step_size) #dist[0]= 0 #plot of the x and y coords. plt.plot(x, y, color='red', lines tyle='solid') plt.plot(x[-1], y(-1), color='black', marker='X') # max absolute value for arrays plt.x_max = np.abs(x).max() plt.y_max = np.abs(y).max() plt.xlim( - x_max , x_max) plt.ylim(-y_max y_max) from random import random import numpy as np def coord(step_size): a = random if a > .50: z = step_size else: z = -step_size return z q = coord(3) print(q) def make_walk (n_timesteps, step_size): n_timesteps = 10000 step_size = 3 x = np.empty(n_times teps, float) y = np.empty(n_timesteps, float) x[@]= 0 y[0]= 0 for i in range (i, n_timesteps): x[i] = x[i - i] coord(step_size) y[i] = yli - 1] + coord(step_size) return x,y #def mag (x,y): mag = ((np.sqrt( x ** 2),y ** 2)) # print (mag) # import numpy as np import matplotlib.pyplot as plt from randomwalker import coord , make_walk x = make_walk(n_timesteps, step_size) #dist[0]= 0 #plot of the x and y coords. plt.plot(x, y, color='red', lines tyle='solid') plt.plot(x[-1], y(-1), color='black', marker='X') # max absolute value for arrays plt.x_max = np.abs(x).max() plt.y_max = np.abs(y).max() plt.xlim( - x_max , x_max) plt.ylim(-y_max y_max)

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!