%Single-channel service system with limited queue
P=[];v=[];w=[];W=[];A=[];
M=5;%number of states=queue+2
o=1;%position of graph of the grid 1x2
n=1/2;%density of demand flow
m=.5/2;%density of service flow 
ra=n/m%their ratio
%The matrix
P=zeros(M);
for i=1:M-1;P(i+1,i)=n;P(i,i+1)=m;end;for i=1:M;P(i,i)=1-sum(P(:,i));end
[v,w]=eig(P);W=diag(w)';
for i=1:M;if abs(W(i)-1)<10^(-5);f=i;end;end;f
Sa=v(:,f)./sum(v(:,f))%asymptotic state
line=[1:1:M-2]*Sa(3:M)%mean number of demands in the queue
time=line/n%mean time of standing in queue
%graph of asymptotic states
figure(1);
subplot(2,2,o);bar(Sa);grid on;axis([.4 8.6 0 .6])