% Generate scaled symmetric random walk paths:
%
% Jan 2017
clear
M = input('enter the number of paths: ');
N = input('enter the number of steps: ');
y = zeros(M,N+1);
x = zeros(M,N);
w = rand(M,N);
for i=1:M
    for j=1:N
        if w(i,j) < 0.5
            x(i,j) = 1;
        else
            x(i,j) = -1;
        end
    end
end

% generate random walk paths:
for k=1:N
    y(:,k+1) = y(:,k) + x(:,k)/sqrt(N);
end


for l=1:M
    plot(y(l,:),'r');
end
xlabel('time'); 
ylabel('y');
title('Scaled Random Walk Paths');
%axis([0 T 0 5]);