Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB CODE The theory for random walks form the basis of many stochastic simulations. For this lab, we will simulate a simple random walk on

MATLAB CODE

The theory for random walks form the basis of many stochastic simulations. For this lab, we will simulate a simple random walk on a 2D lattice. A simple analogy for this random walk is to imagine a drunk guy standing at the origin (0,0). He has an equal chance to move either north (0,1), south (0,-1), east (1,0) or west (-1,0). (Recall the guy with amnesia having to find his way out of the mine and how he had an equal probability of any path because he couldnt remember). When the drunk guy reaches his new destination, the same choice is repeated and he can go in each of the 4 directions again with equal probability. This process is repeated indefinitely. For example, a random path can be: (0,0) to (0,1) to (1,1) to (1,2) to (0,2) to (-1,2) ..........

One way to code this is MatLab is: 1. Define a position matrix of size (N + 1)2, where N is the number of steps. Initialize the first row to be (0,0) since he is starting at the origin. 2. Create a for loop which goes through each row i from 1 to N. Use a random number generator, the current position (row i) and if-else statements to decide the next position (row i+1). This will be similar to the if-else statements and random number generators used in the miner lab. 3. Once the loop is done, you should have the matrix for all of the positions at each step.

Problem 1

Plot these positions for one trial after N=10,20,100 steps. I.E. plot(M(1:N+1,1),M(1:N+1,2)) where M is the matrix you just filled. Indicate the points after these steps (one way could be plot(M(N+1,1),M(N+1,2),go)) where g could be replaced by any color, o by another symbol. What is the maximal distance from the origin our drunkard has gone after 100 steps?

Problem 2.

For k = 1000 simulations (Monte Carlo), find the probability that after 100 steps, the person is ten or more units away from the origin in either direction. In other words, if the final coordinate is denoted (x,y), what is the probability that |x| 10 or |y| 10 after k simulations?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago