% ### EXrandomWalk1D.m ### 11.15.14 % Calculates mean-squared distance for a group of independent 1-D random % walkers, each moving with user-specified probablity of one step left vs right % [Source (modified): Kevin Berwick (re 'Computational Physics', Giordano & Nakanishi)] clear; % ------------- N= 200; % Total # of (independent) walkers (each starts at x=0) M= 100; % Total # of steps for each walker K= 3; % # of walkers to show individual traces for [3] bias= 0.5; % number between [0,1] to indicate bias for left vs right (0.5= equal prob.) % ------------- % +++ step_number= zeros(1,M); % x2ave= zeros(1,M); % allocate array to stored (suquentially averaged) MSD step_number_array= [1:1:M]; % % +++ % % NOTE: the loop is set up in such a way to average x2ave across walkers for r= 1:N x=0; % initialize position for r'th walker position(r,1)= 0; % loop to go through M steps for r'th walker for nn=1:M; % conditional determines whether step is to the left or right if (rand