1function [G,R,U]=QBD_CR(A0,A1,A2,varargin)
2%QBD_CR Cyclic reduction
for Quasi-Birth-Death Markov Chains [Bini,Meini]
6% G=QBD_CR(A0,A1,A2) computes the minimal nonnegative solution to the
7% matrix equation G = A0 + A1 G + A2 G^2, where A,B and C are square
8% nonnegative matrices, with (A0+A1+A2) irreducible and stochastic
10% [G,R]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
11% to the matrix equation R = A2 + R A1 + R^2 A0
13% [G,R,U]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
14% to the matrix equation U = A1 + A2 (I-U)^(-1) A0
16% CONTINUOUS TIME CASE:
18% G=QBD_CR(A0,A1,A2) computes the minimal nonnegative solution to the
19% matrix equation 0 = A0 + A1 G + A2 G^2, where A,B and C are square
20% nonnegative matrices, with (A0+A1+A2) having row sums equal to zero
22% [G,R]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
23% to the matrix equation 0 = A2 + R A1 + R^2 A0
25% [G,R,U]=QBD_CR(A0,A1,A2) also provides the minimal nonnegative solution
26% to the matrix equation U = A1 + A2 (-U)^(-1) A0
30% MaxNumIt: Maximum number of iterations (default: 50)
31% Verbose: The residual error
is printed at each step when set to 1,
33% Mode:
'Basic' uses the Basic Cyclic Reduction
34%
'Shift' uses the shift technique to accelarate convergence
36% RAPComp: set to 1 if the QBD has RAP components
50OptionValues{1}=[
'Basic';
54for i=1:size(OptionNames,1)
55 options.(deblank(OptionNames(i,:)))=[];
59%options.ProgressBar=0;
65% Parse Optional Parameters
66options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
69 % Convert to discrete time problem, if needed
72 if (sum(diag(A1)<0)) % continues time
81 QBD_ParsePara(A0,A1,A2);
84 QBD_RAP_ParsePara(A0,A1,A2);
86 % Convert to discrete time problem - uniformization
95% check whether G
is known explicitly
96[G,R,U]=QBD_EG(A0,A1,A2,options.Verbose,nargout);
104if (options.Mode=='Shift')
105 theta=stat(A0+A1+A2);
106 drift=theta*sum(A0,2)-theta*sum(A2,2);
107 if (drift < 0) % MC
is transient -> use the dual MC
108 if (nargout > 1 | options.Verbose==1)
111 A2=A2-ones(m,1)*(theta*A2);
112 A1=A1+ones(m,1)*(theta*A0);
115 if (nargout > 2 | options.Verbose==1) % store A0old to compute U
123% Start of Cyclic Reduction (Basic)
127if (nargout <= 1 & options.Verbose ~= 1) % A1 and A2 only needed to compute R
131%if (options.ProgressBar==1)
132% progressBar2(0,'Quasi-Birth-Death','Computing R via Cyclic Reduction (CR) ...');
136while (check > 10^(-14) & numit < options.MaxNumIt)
137 Atemp=(eye(m)-A)^(-1);
141 A=A+BAtemp*C+Atemp*B;
145 check=min(norm(B,inf),norm(C,inf));
146 %if (options.ProgressBar==1)
147 % est_numit=ceil(log2(log(10^(-50))/log(check/checkold)));
149 % progressBar2(min([1 numit/(numit+est_numit)]),'Quasi-Birth-Death');
151 if (options.Verbose==1)
152 fprintf('Check after %d iterations: %d\n',numit,check);
156if (numit == options.MaxNumIt && check > 10^(-14))
157 warning('Maximum Number of Iterations %d reached',numit);
159clear Atemp BAtemp A B C;
160G=(eye(m)-Ahat)^(-1)*A0;
164if (options.Mode=='Shift')
165 if (drift < 0) % transient
166 if (nargout > 1 | options.Verbose==1)
167 A1=A1-ones(m,1)*theta*A0; % restore original A1
168 A2=A2old; % restore original A2
172 if (nargout > 1 | options.Verbose==1)
173 A1=A1-sum(A2,2)*uT; % restore original A1
175 if (nargout > 2 | options.Verbose==1)
176 A0=A0old; % restore original A0
181if (options.Verbose==1)
182 res_norm=norm(G-A0-(A1+A2*G)*G,inf);
183 fprintf('Final Residual Error for G: %d\n',res_norm);
188 R=A2*(eye(m)-(A1+A2*G))^(-1);
189 if (options.Verbose==1)
190 res_norm=norm(R-A2-R*(A1+R*A0),inf);
191 fprintf('Final Residual Error for R: %d\n',res_norm);
198 if (options.Verbose==1)
199 res_norm=norm(U-A1-A2*(eye(m)-U)^(-1)*A0,inf);
200 fprintf('Final Residual Error for U: %d\n',res_norm);
208%if (options.ProgressBar==1)
209% progressBar2(1,'Quasi-Birth-Death');