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

Part 1 - Random Walks - 9 marks Suppose we have a 2D lattice of size 100 x 100 u

ID: 2966365 • Letter: P

Question

Part 1 - Random Walks - 9 marks

Suppose we have a 2D lattice of size 100 x 100 units, and we position a walker at a

starting point (x0; y0). You are to simulate a random walk on the lattice, taking steps

of length 1 unit with

Case 1: a choice of 4 directions described by the compass points N, E, S and W;

Case 2: a choice of 8 directions N, NE, E, SE, S, SW, W and NW.

In each case, the choice of direction is uniformly distributed. You should consider the

lattice as having a wrap-around property, i.e. if the walker steps off the lattice at the

top (or bottom), s/he appears in the same column at the bottom (or top) of the lattice;

similarly for stepping off one of the sides, with the walker appearing in the same row on

the opposite side.

You are to carry out a random walk with M steps in each path, and calculate the total

displacement at the end of the walk sqrt

(xM - x0)2 + (yM -y0)^2. Simulate N such paths,and compute the average displacement.

Your code should be in MATLAB, and should accept input parameters M and N, as well

as a flag indicating the choice of 4 or 8 directions. You should plot a figure in MATLAB

showing the average displacement versus M, for M = 49; 64; 100; 144 steps for each of

Cases 1 and 2.

You should also write a paragraph, where you discuss your answer interpreting the

average displacement result and also justifying your choice of the value of N that you

use.

Part 2 - Sampling from Experimental Data - 6 marks

The data file inputData60.txt contains 60 samples of data from some experiments. In

MATLAB, construct the distribution function F(x) for this data and generate 300 ran-

dom variables from this distribution. Plot both the histogram of the experimental data

and your generated data, to confirm that they seem to belong to the same probability

distribution.

inputData60.txt

    0.2969

    0.4242

    0.4445

    0.0891

    0.1390

    0.0782

    0.3479

    0.6249

    0.6616

    0.1152

    0.2660

    0.2118

    0.7137

    0.1306

    0.7318

    0.7015

    0.7226

    0.1407

    0.6894

    0.1883

    0.5507

    0.2377

    0.2812

    0.7232

    0.6528

    0.4864

    0.0835

    0.1478

    0.3133

    0.6707

    0.2609

    0.2245

    0.4043

    0.1014

    0.5780

    0.5932

    0.4653

    0.3303

    0.6138

    0.1998

    0.6870

    0.1774

    0.1670

    0.3629

    0.1572

    0.5077

    0.5292

    0.3850

    0.2516

    0.7298

    0.1081

    0.6338

    0.7094

    0.4486

    0.1227

    0.5720

    0.7294

    0.3661

    0.5198

    0.0951

Explanation / Answer

delta_x=0.1; %length of space step tau=0.01; %length of time step M=100; %number of time steps T=tau*M; %end time N=1000; %number of particls pos=zeros(1,N); %all particles start at x=0 p_l=.5; %probability of moving left p_r=.5; %probability of moving right t=0; %counts passage of time %Simulate the random walk process while t