Question: How do I make a plot for random walk problem?

Hi!

I'm doing an assignment where we are supposed to create a random walk with 3 options (go straight forward, turn left, turn right), and the first step is to be taken to [1,0]. I am supposed to plot the result afterwards, but when I plot it, it's empty...

(The first # is forward, the second # is to the right, and the third # is to the left)

for i to M0 do

X[i, 0] := 1; Y[i, 0] := 0;

for j from 2 to M1 do

r := R3();

if r = 1 then X[i, j] := 2*X[i-1, j]-X[i-2, j]; Y[i, j] := 2*Y[i-1, j]-Y[i-2, j];

elif r = 2 then X[i, j] := X[i-1, j]+Y[i-1, j]-Y[i-2, j]; Y[i, j] := Y[i-1, j]-X[i-1, j]+X[1-2, j];

else X[i, j] := X[i-1, j]-Y[i-1, j]+Y[i-2, j]; Y[i, j] := Y[i-1, j]+X[i-1, j]-X[i-2, j];

end if;

end do;

end do:

Then, for the plot:

plot([[[([X[i, j], Y[i, j]], $j = 0 .. M1)], $i = 1 .. M0)], scaling = CONSTRAINED);

This is what I got for the plot:

Where have I gone wrong? 

Thanks in advance!

Please Wait...