clear all
steplen=1;
startx=0;
starty=0;
nsteps=100;
nsamples=2000;
angle=2*pi*rand(nsteps,nsamples);
dx=steplen*cos(angle);
dy=steplen*sin(angle);
for j=1:nsamples
    x(1)=startx;
    y(1)=starty;
    for i=2:nsteps
        x(i)=x(i-1)+dx(i-1,j);
        y(i)=y(i-1)+dy(i-1,j);
    end
    distance(:,j)=sqrt(x.^2+y.^2);
end
meandists=mean(distance')';
t=1:numel(x);
loglog(t,meandists)
xlabel('time')
ylabel('mean distance traveled')
title('Mean Distance Traveled vs. Time')
axis([1 nsteps steplen 10])
