1function qlen=GIM1_qlen_ETAQA(B,A,R,pi, n,varargin)
2%GIM1_qlen_ETAQA returns the n-th moment of queue length of a
3%GIM1/M/1 process
using the ETAQA method [Riska, Smirni]
7% qlen=GIM1_qlen_ETAQA(B,A,pi,R,n) computes the n-th
8% moment of an GI/M/1-type Markov chain with an
9% infinitesimal generator matrix of the form
18% the input matrix R
is the minimal nonnegative solution to the
19% matrix equation 0 = A0 + R A1 + R^2 A2 + ... + R^maxa Amaxa
20% The input matrix B equals [B1; B2; ...; Bmaxb], the input
21% matrix A equals [A0;A1;A2; ...; Amaxa]
26% Boundary: B0, which allows solving the GI/M/1 Type CTMC
27% with a more general boundary states block
31% Q = B3 A2 A1 A0 0 ...
34% The matrices B0 need not to be
35% square. (
default: B0=A0)
37OptionNames = [
'Boundary '];
38OptionTypes = [
'numeric'];
42for i=1:size(OptionNames,1)
43 options.(deblank(OptionNames(i,:)))=[];
46% Parse Optional Parameters
47options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
52if (mod(size(B,1)-mb,m) ~= 0)
53 error('MATLAB:GIM1_qlen_ETAQA: input matrix B has incorrect number of rows');
55 degb = (size(B,1)-mb)/m;
58if (mod(size(A,1),m) ~= 0)
59 error('MATLAB:GIM1_qlen_ETAQA: input matrix A has incorrect number of rows');
61 dega = (size(A,1))/m-1;
65if( max(temp<-100*eps))
66 error('MATLAB:GIM1_qlen_ETAQA:InvalidRInput',...
67 'The spectral radius of R
is not below 1: GIM1
is not pos. recurrent');
70if (~isempty(options.Boundary))
71 B0 = options.Boundary;
75 error('MATLAB:GIM1_qlen_ETAQA:input options.Boundary has incorrect number of rows');
78 error('MATLAB:GIM1_qlen_ETAQA:input options.Boundary has incorrect number of columns');
86pistar = pi(mb+m+1:mb+2*m);
95if abs((sum(test,2) - ones(mb,1))'*ones(mb,1)) < 1e-10
96 % transform from DTMC to CTMC
97 B(1:mb,:) = B(1:mb,:) - eye(mb);
98 A(m+1:2*m,:) = A(m+1:2*m,:) - eye(m);
104lsum = A(1:m,:) + A(m+1:2*m,:);
106 lsum = lsum + Rpower*A(i*m+1:(i+1)*m,:);
114leftr_part1 = zeros(m,m);
115leftr_part2 = zeros(m,m);
116if degb >= 2 && dega >= 2
120 leftr_part1 = leftr_part1 + Rpower*A((i+2)*m+1:(i+3)*m,:);
121 leftr_part2 = leftr_part2 + i*Rpower*A((i+2)*m+1:(i+3)*m,:);
125 leftr = leftr_part1*ones(m,1) + leftr_part2*ones(m,1) - A(1:m,:)*ones(m,1);
128 if (degb == 1 && dega ~= 1)
131 leftr = leftr + (i-1)*Rpower*A(i*m+1:(i+1)*m,:);
134 leftr = leftr*ones(m,1) - A(1:m,:)*ones(m,1);
136 error('MATLAB:GIM1_qlen_ETAQA: the number of A blocks
is not enough, this
is a reducible Markov Chain!');
143% lsum
is one matrix and leftr
is one column
144lsleft = [lsum(:,1:end-1),leftr];
150% newly added here, calculate the unchanged part in the+ factor on the right
151% it
is -sum_j=2 to inf {(j-1)*R^(j-1)*Bhat(j)}
152tempsum = zeros(m,mb);
155 tempsum = tempsum + i*Rpower*getVerticalBlock(B,m,(i+2));
158 rsidepart22 = pi1*(-tempsum*ones(mb,1));
159% compute the reusable part of the right hand side of
this equation
164% have to check n to see
if it
is greater than 1
165% get the reusable array, every column corresponds to a vector, starting from j=1
166% F - sum_j=1 to inf {(sum_m=1 to j{m^l}) R^(j)*B^(j+1)}
171 tempsum = tempsum + i*Rpower*getVerticalBlock(A,m,i+3);
179 % bk
is the first part of the right side of the equation
180 bk = (-1)*(pi0*2^k*B0 + pi1*(2^k*A(m+1:2*m,:) + 3^k*A(1:m,:)));
183 bk = bk + (-1)*bino(k,l)*r(k-l+1,:)*(A(m+1:2*m,:) + 2^l*A(1:m,:));
188 % now compute the second part of the equations system
189 tempsum = zeros(m,m);
198 tempsum = tempsum + temp*Rpower*getVerticalBlock(A,m,i+3);
202 rsidepart2reuse(:,end+1)=(A(1:m,:)-tempsum)*ones(m,1);
204 ck = pi1*2^k*A(1:m,:)*ones(m,1);
205 tempsum2 = zeros(m,mb);
212 tempsum2 = tempsum2 + temp*Rpower*B(mb + (i-1)*m+1:mb + (i)*m,:);
215 ckresttemp = pi1*tempsum2*ones(mb,1);
216 ck = ck - ckresttemp;
221 ckrest = ckrest + bino(k,l) * r(k-l+1,:)*(rsidepart2reuse(:,l));
230qlen = sum(r(end,:),2) + sum(pi1,2);
234 function b = bino(n,k)
235 b = factorial(n)/(factorial(k)*factorial(n-k));
238 function m = getVerticalBlock(Mn,blockrow,i)
241 m = Mn(blockrow*(i-1)+1:blockrow*i,:);