% Number of times to run the simulation Mall = [100 1000 10000 100000]; % Matrix holding the 21 probabilities for each value of M p = zeros(21,length(Mall)); % Loop over M values for midx = 1:length(Mall) M = Mall(midx) % y postion at the end of each 10 step simulation last_stop = zeros(M,1); for idx = 1:M mash_walk = mash(10); last_stop(idx) = mash_walk(end,2); end % Collect the statistics on the y position at the end of each stop % The vector p will hold the probabilities for idx = -10:10 tmp = sum(last_stop==idx)/M; p(idx+11,midx) = tmp; end end % Display the results figure(1);clf subplot(221) stem(-10:10,p(:,1));xlabel('y position');title('N = 100') subplot(222) stem(-10:10,p(:,2));xlabel('y position');title('N = 1000') subplot(223) stem(-10:10,p(:,3));xlabel('y position');title('N = 10000') subplot(224) stem(-10:10,p(:,4));xlabel('y position');title('N = 100000') print -djpeg ps02p1.jpg