% % macm 202 -- 11 feb 03 -- djm % % w6gap0.m: simulate street crossing process % % - use direct exponential distribution % - many K-values (K=mu*T) clear; kk = []; kmean =[]; kvar = []; for K = 0.2:0.2:2.0; mu = 1; walk = K/mu; w6gap1 kk = [kk K]; kmean = [kmean out(1)]; kvar = [kvar out(2)]; end close all % plot means & vars T = 0:0.05:2.0; subplot(2,1,1) plot(T,exp(T)-1,'r') hold on plot(kk,kmean,'o') title('\bf mean # of cars: theory vs simulation') xlabel('\bf T: time to cross') ylabel('\bf mean(T)') subplot(2,1,2) plot(T,(exp(T)-1).^2 + exp(T)-1,'r') hold on plot(kk,kvar,'x') title('\bf variance # of cars: theory vs simulation') xlabel('\bf T: time to cross') ylabel('\bf var(T)')