%RANDOM WALK TO BROWNIAN MOTION

clf reset;
maxn=1000;

%simple random walk
rv=sqrt(3)*(2*(rand(1,maxn)<0.5)-1); 

%uniform steps 
rv=2*rand(1,maxn)-1; 


for (n=[20 40 1000])

%%% parameters
   dt=1/n;
   t=[0:dt:1]; 
   vec=zeros(1,n);
   
   vec(1:n)=rv(1:n);
   Bmt = [0 cumsum(sqrt(dt)*vec)];
   
   if (n<=50)
       cv=[n/50,1-n/50, 0];
   else
       cv=[0 0 1];
   end 
   plot(t,Bmt,'Color',cv);
   hold on; 
   
end

title('Random walks to Brownian motion');

