% /M/PH/1(k);
% p=stationary_prob(4,beta,S,order,lambda);
function [p,p_minus,p_add,mean,time]=stationary_prob(k,beta,S,lambda) order=length(beta);
e=ones(order,1);
R=lambda*inv(lambda*eye(size(S))-lambda*e*beta-S);
R_k=eye(size(S));
for i=1:k
R_k = R_k+R^i;
end
p0=inv(beta*(R_k-lambda*R^k*inv(S))*e);
p_t=p0;
for i=1:k
p_t=[p_t,p0*beta*R^i];
end
p_t=[p_t,p0*beta*(R^k)*(-lambda*inv(S))];
% the queue length distribution in any time
% add every phase in the same level
p=p0;
for i=1:k+1
sum=0;
for j=1:order
sum =sum+p_t(1+(i-1)*order+j);
end
p=[p,sum];
end
p_minus = p;
% the queue length distribution at departure
% p_add = p_minus(i)/(1-p_minus(k+1))
p_add=[0];
for i=0:k
p_add=[p(k-i+1)/(1-p(k+2)),p_add];
end
% the mean queue length
mean=0;
for i=1:k
mean =mean+i*p(i+1);
end