Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Restart your subscription to keep accessing solutions. Your Chegg Study subscrip

ID: 3841456 • Letter: R

Question

Restart your subscription to keep accessing solutions. Your Chegg Study subscription will expire on May 24, 2017. CONTINUE MY SUBSCRIPTION home / study / engineering / computer science / questions and answers / can someone show me how to make a 2d random walk ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Can someone show me how to make a 2d random walk o... Bookmark can someone show me how to make a 2d random walk on python. I want to graph x vs t. the walk should be over a perod of 10000 steps each step per second. It should also randomize the dirsction of the theta between each step

Explanation / Answer

Below is the code , let me know in comments if you have queries

from random import randrange as rand

from numpy import cos, sin, radians

import numpy as np

import matplotlib.pyplot as plt

N = 100   # Size of square as a multiple of the step size.

NSteps = 10000 # Number of steps in simulation.

xStart = 0   # x coordinate of starting location. Origin is at middle of square

yStart = 0   # y coordinate of starting location. Origin is at middle of square

s = 1   # Step number.

x = xStart   # x coordinate of point.

y = yStart   # y coordinate of point.

xList = []   # List of the x coordinates of all points visited.

yList = []   # List of the y coordinates of all points visited.

def wrap(v, N):

    if v > N/2:

        return v - N, True

    elif v < -N/2:

        return v + N, True

    return v, False

for j in range(NSteps):

    angle = radians(rand(361))

    x, wrap_flag_x = wrap(x + cos(angle), N)

    y, wrap_flag_y = wrap(y + sin(angle), N)

    if wrap_flag_x or wrap_flag_y:

        xList.append(np.nan)

        yList.append(np.nan)

    xList.append(x)

yList.append(y)   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote