1function qlen=MG1_qlen_ETAQA(B,A,pi,n,varargin)
2%MG1_qlen_ETAQA returns the n-th moment of queue length of a
3%M/G/1 process
using the ETAQA method [Riska, Smirni]
7% qlen=MG1_qlen_ETAQA(B,A,pi,n) computes the n-th
8% moment of an M/G/1-type Markov chain with an
9% infinitesimal generator matrix of the form
13% Q = 0 A0 A1 A2 A3 ...
17% the input matrix A = [A0 A1 ... Aamax] and B = [B0 B1
18% B2 ... Bbmax], pi
is the aggregated probability computed from ETAQA
21% pi=MG1_qlen_ETAQA([],A,pi,n) computes the stationary
22% vector of an M/G/1-type Markov chain with an
23% infinitesimal generator matrix of the form
27% Q = 0 A0 A1 A2 A3 ...
33% Boundary: Allows solving the MG1 type Markov chain
34% with a more general boundary:
40% the parameter value contains the matrix C0.
41% The matrices C0 and B1,B2,... need not to be
42% square. (
default: C0=A0)
45OptionNames = [
'Boundary '];
46OptionTypes = [
'numeric'];
50for i=1:size(OptionNames,1)
51 options.(deblank(OptionNames(i,:)))=[];
54% Parse Optional Parameters
55options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
58m=size(A,1); % number of states for the repetitive structure
59dega=size(A,2)/m-1; % amax,
# of A blocks - 1
62 mb=m; % number boudary states
67 if (mod(size(B,2)-mb,m) ~= 0)
68 error(
'Matrix B has an incorrect number of columns');
70 degb = (size(B,2)-mb)/m; % bmax
73if (isempty(options.Boundary))
76 C0 = options.Boundary;
79if (isempty(options.Boundary) & mb ~= m)
80 error(
'The Boundary option must be used since the column size of B0 is not identical to A0');
83if (~isempty(options.Boundary))
84 if (size(options.Boundary,1) ~= m | size(options.Boundary,2) ~= mb)
85 error(
'The boundary parameter value has an incorrect dimension');
89if ( abs(sum(pi,2)-1) > 1e-10 )
90 error(
'The input probability vector does not sum up to 1');
93if ( mod(size(pi,2)-mb,m) ~=0 )
94 error(
'Matlab:MG1_qlen_ETAQA:IncorrectDimension',...
95 'The probability vector has an incorrect number of columns');
99pistar = pi(:,mb+m+1:mb+2*m);
102% Provide the linear system r[k]*[(A0+A1+A2+...),(A(2)+2A(3)+3A(4)+...)*e]=[b[k],c[k]];
103% b[k] = - fhat(k) - f(k) - sum_l=(1 to k) binomial(k,l)*r[k-l]*(A1+sum_j=1 (j+1)^l*A(j+1))
104% c[k] = - fchat(k) - fc(k) - sum_l=1,k binomial(k,l)*r[k-l]*sum_j=1 j^l F(0,j)*e
107 Asum = Asum + A(:,i*m+1:(i+1)*m);
111 F11=F11+(i-1)*A(:,i*m+1:(i+1)*m);
113Asum = Asum(:,1:end-1);
114lsleft = [Asum,(F11-A(:,1:m))*ones(m,1)];
118% Fhat0(j) = sum_l=j B(l), j>=1
119Fhat0j=B(:,mb+(degb-1)*m+1:end);
121 temp = B(:,mb+(j-1)*m+1:mb+j*m) + Fhat0j(:,1:m);
122 Fhat0j = [temp,Fhat0j];
125% F0(j) = sum_l=j A(l+1), j>=1
126F0j = A(:,dega*m+1:end);
128 temp = A(:,j*m+1:(j+1)*m) + F0j(:,1:m);
134% preparation
for compute the repetitive part in the righthand side of the equation
135% frestsaver and fckrestsaver are the components reusable
136% frestsaver(l) = sum_j=1 (j+1)^l*A(j+1), l = 1:n
137% fckrestsaver(l) = sum_j=1 j^l*F0j(j), l = 1:n
143 temp = temp + j^l*A(:,j*m+1:(j+1)*m);
145 frestsaver{end+1} = temp;
148 if (j <= size(F0j,2)/m)
149 temp = temp + j^l*F0j(:,(j-1)*m+1:j*m);
152 fcrestsaver{end+1} = temp;
156 % fhat(k) = pi0 * (sum_j=1 (j+1)^k*B(j))
159 fhatk = fhatk + (j+1)^k*B(:,mb+(j-1)*m+1:mb+j*m);
162 % f(k) = pi1* (2^k*A(1) + sum_j=1 (j+2)^k*A(j+1))
165 fk = fk + (j+1)^k*A(:,j*m+1:(j+1)*m);
167 fk = 2^k*A(:,m+1:2*m) + fk;
169 % frest = sum_l=(1 to k) bino(k,l)r[k-l]*(A(1)+sum_j=1 (j+1)^l A(j+1))
172 frest = frest + bino(k,l)*r(k-l+1,:)*(A(:,m+1:2*m) + frestsaver{l});
174 % bktemp = -fhatk - fk - frest
175 % bk = bktemp - last column
176 bk = (-1)*fhatk + (-1)*fk + (-1)*frest;
178 % fchatk = pi0*(sum_j=2 j^k Fhat0j(j)*e)
179 % fck = pi1*(sum_j=1 (j+1)^k*F0j(j)*e)
180 % fcrest = sum_l=1 (bino(k,l)r[k-l]*sum_j=1 j^l*F0j(j)*e)
183 fchatk = fchatk + (j^k)*Fhat0j(:,(j-1)*m+1:j*m);
185 fchatk = pi0*fchatk*ones(m,1);
188 fck = fck + (j+1)^k*F0j(:,(j-1)*m+1:j*m);
190 fck = pi1*fck*ones(m,1);
193 fcrest = fcrest + bino(k,l)*r(k-l+1,:)*fcrestsaver{l};
195 fcrest = fcrest*ones(m,1);
196 ck = - fchatk - fck - fcrest;
204 function b = bino(n,k)
205 b = factorial(n)/(factorial(k)*factorial(n-k));
209qlen = sum(r(end,:),2) + sum(pi1,2);