Question

A random walk is a particular kind of probabilistic (pseudo-random) simulation that models certai...

A random walk is a particular kind of probabilistic (pseudo-random) simulation that models certain statistical systems, such as Brownian motion of particles or molecules. Coin flipping is an example of a one-dimensional random walk--one dimensional because you only can go forward (when you flip heads) or backward (when you flip tails) along a straight line. Suppose you take a random walk of nsteps. How many steps away from your starting point would you expect to end up on average, if you repeated the experiment many times? Now suppose we make it two-dimensional. Suppose you can go forward, backward, left and right. How many steps away from your starting point would you expect to end up on average, if you repeated this experiment many times? And finally, suppose instead of just four choices, we could go one unit step any direction? We can generate a random direction using an angle from the x axis and move one step. Your program should take the number of steps and number of trials as input. Assume the walker always starts at 0,0 in the middle of an infinite-unit grid for any given walk. One walk == one trial. Create a graphical program that will put a dot on the grid where the walker ends each walk. At the end, print out the number of steps, number of trials, straight-line distance and actual distance traveled to the console or GUI. Display values to 3 decimal places.

import math
import random
import turtle

#function to calculate the distance between 2 points
def distance(x1, y1, x2, y2):
dx = x1 - x2;
dy = y1 - y2;
dist = math.sqrt(dx * dx + dy * dy);
return dist


def main():

#prompt and get the number of steps
steps = int(input('How many steps? '))
trails = int(input("how many trails?"))
  
#initialize
x1 = 0
y1 = 0
actualDistance = 0
s = turtle.Screen()
t = turtle.Turtle()
t.color('red')

#iterate for no.of steps specified
for k in range(steps):
#use formula to get next values
angle = random.random() * 2 * math.pi
x2 = x1 + math.cos(angle)
y2 = y1 + math.sin(angle)
trails =
#print('(%d, %d)' % (x2, y2))
actualDistance = actualDistance + distance(x1, y1, x2, y2)
t.left(angle) #turn the tutle
t.goto(x2, y2) #goto new location
x1 = x2
y1 = y2
  
  
  
#calcuate the straightline distance between origin and final position
straightDistance = distance(0, 0, x1, y1)
print('Actual distance is %.2f and straight line distance is %.2f' % (actualDistance, straightDistance))
  
s.exitonclick()

if __name__ == "__main__":
main()
I used this code, but I need to find out about how many trails.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Soluton #fre vahe for no. For kinage [steps] #use foynula to Jer next values 2 ya Single Ya] # caliculate He Styagh, line dname_. main- mein

Add a comment
Know the answer?
Add Answer to:
A random walk is a particular kind of probabilistic (pseudo-random) simulation that models certai...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1: Random Walk A random walk is a stochastic process. A stochastic process is a series of...

    python / visual studio Problem 1: Random Walk A random walk is a stochastic process. A stochastic process is a series of values that are not determined functionally, but probabilistically. The random walk is supposed to describe an inebriated person who, starting from the bar, intends to walk home, but because of intoxication instead randomly takes single steps either forward or backward, left or right. The person has no memory of any steps taken, so theoretically, the person shouldn't move...

  • python / visual studio Problem 1: Random Walk A random walk is a stochastic process. A...

    python / visual studio Problem 1: Random Walk A random walk is a stochastic process. A stochastic process is a series of values that are not determined functionally, but probabilistically. The random walk is supposed to describe an inebriated person who, starting from the bar, intends to walk home, but because of intoxication instead randomly takes single steps either forward or backward, left or right. The person has no memory of any steps taken, so theoretically, the person shouldn't move...

  • (Intro to Java help?) Define a class named RandomWalker. A RandomWalker object should keep track of...

    (Intro to Java help?) Define a class named RandomWalker. A RandomWalker object should keep track of its (x, y) location. All walkers start at the coordinates (0, 0). When a walker is asked to move, it randomly moves either left, right, up or down. Each of these four moves should occur with equal probability. The resulting behavior is known as a "random walk." (A 2-dimensional random walk example is pictured at right.) Each RandomWalker object should have the following public...

  • I am programing an Extended Kalman Filter , with noise but not getting correct answer ....

    I am programing an Extended Kalman Filter , with noise but not getting correct answer . this is my code # ---------- # Part Two # # Now we'll make the scenario a bit more realistic. Now Traxbot's # sensor measurements are a bit noisy (though its motions are still # completetly noise-free and it still moves in an almost-circle). # You'll have to write a function that takes as input the next # noisy (x, y) sensor measurement and...

  • INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the...

    INSTRUCTIONS: I NEED TO CREATE A PointApp PROGRAM THAT USES THE FOLLOWING API DOCUMENTATION. Below the API Documentation is the code I submitted. However, the output is different for what they are asking. I am looking for someone to fix the code to print out the correct output and to add comments so I can have an idea in how the code works. PLEASE AND THANK YOU. API DOCUMENTATION: public class Point extends java.lang.Object The Point class is used to...

  • Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the...

    Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the game scenario, you are a vampire hunting a victim in a dark cave. The cave consists of 10 by 10 little squares, numbered 0-9 on each side; your victim is in the cave, with x-coordinate and y-coordinate 0-9 (both integers). On each turn, you guess where your victim is, and try to bite her/him. Your “health” is determined by the number of bloodpoints you...

  • In this problem you'll get to use one of Java's random number generators, java.util.Random (see the...

    In this problem you'll get to use one of Java's random number generators, java.util.Random (see the docs for Random). This class generates a random double precision number uniformly distributed in the range [0.0 ... 1.0). That is, the numbers go from 0 to 1, including 0 but excluding 1. It is a common need in Java programming to generate a random integer number that's uniformly distributed in the range of [0 ... n), such as we saw in the dice...

  • How can I get started in this program for this DelivC?

    SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...

  • Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of...

    Python. Just work in the def sierpinski. No output needed. Will give thumbs up for any attempt beginning this code. Your task is to implement this algorithm in Python, returning a random collection of inum-100, 000 points. You should then plot the points to see the structure. Please complete the following function: def sierpinski (po, v, f, inum) The four arguments are ·po the initial point. You may assume this is the origin, i.e., po = [0, 0] . v:...

  • Question 2 - Programming Exercise 1. Make a directory for this lab and change into it....

    Question 2 - Programming Exercise 1. Make a directory for this lab and change into it. 2. Copy files using the following command: cp/net/data/ftp/pub/class/115/ftp/cpp/Inheritance/Exercise.cpp Exercise.cpp Finish the program so that it compiles and runs. The instructions are contained in the C++ file. Your completed program should generate output similar to the following: TwoD default constructor This program asks for the coordinates of two points in 3D space and calculates their distance. Please enter the xyz coordinates for the first point:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT