% % Written by: % -- % John L. Weatherwax 2007-09-10 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clc; close all; drawnow; % get code to simulate a sample path corresponding to a M/M/1 queue: addpath( '../Chapter8' ); T = 20; lambda = 0.2; mean_at = 1/lambda; fprintf( 'mean arrival time (mean_at) = %10.6f\n', mean_at ); [t,Ni,Ei,Ai,Di] = chap_8_prob_13(T,mean_at,5,10); figure; stairs(t,Ni,'-b'); axis( [ min(t), max(t), 0, max(Ni)+0.5 ] ); xlabel('time'); ylabel('number in system'); title( 'number of customers in the queue' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter11/', 'epsc' ); figure; sh1=stairs(t,Ai,'-r'); hold on; sh2=stairs(t,Di,'-g'); axis( [ min(t), max(t), 0, max([Ai(:);Di(:)])+0.5 ] ); xlabel('time'); ylabel('number'); title( 'A(t) and D(t)' ); legend( [sh1,sh2], {'A(t) total number of arrivals by time t','D(t) total number of departures by time t'}, ... 'location', 'northwest' ); saveas( gcf, '../../WriteUp/Graphics/Chapter11/chap_11_prob_1_At_N_Dt', 'epsc' ); Li = Ai-Di; figure; shL=stairs(t,Li,'-r'); axis( [ min(t), max(t), 0, max(Li(:))+0.5 ] ); xlabel('time'); ylabel('number'); title( 'L(t)' ); saveas( gcf, '../../WriteUp/Graphics/Chapter11/chap_11_prob_1_Lt', 'epsc' ); % compute some average queue statistics: tL = trapz(t,Li); L_20 = tL/T; W_20 = tL/Ai(end); l_20 = Ai(end)/T; fprintf('L(20) = %10.6f; W(20) = %10.6f; lambda_a(20) = %10.6f\n', L_20, W_20, l_20 ); clear functions;