%
%  math495/stat490 -- 24 nov 03 -- djm
%
%  w13bridge.m:  

clear;

%  walk parameters
T = 2;  WT = 1.0;  sig2 = 1.0;  mu = 1.0;
Nst = 500;  dt = T/Nst;  dx = sqrt(sig2*dt);

%  initialize random number generator
phone = 2914814;
rand('state',phone);  %  initialize with my office phone number

%  plot 10 sample random walks
figure(3);  clf;  hold on
time = [0;dt*(1:Nst)'];  

Nw1 = 10;
walkers = zeros(Nw1,1);

for j = 1:Nst
    walkers = (1-mu*dt)*walkers + (2*(rand(Nw1,1)>0.5)-1)*dx;
    plot(j*dt,walkers,'.')
end
title('\bf 10 random walks with decay & \pm \surdvariance curves (5000 walks)')
ylabel('\bf Z(T)-axis')
xlabel('\bf T-axis')
pause(1)

%  gather statistics for 5000 walks
Nw1 = 5000;
walkers = zeros(Nw1,1);
Zvar = zeros(size(time));

for j = 1:Nst
    walkers = (1-mu*dt)*walkers + (2*(rand(Nw1,1)>0.5)-1)*dx;
    Zvar(j+1) = var(walkers);
end
plot(time, sqrt(Zvar),'k')
plot(time,-sqrt(Zvar),'k')
