LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
QBD_FI.m
1function [G,R,U]=QBD_FI(A0,A1,A2,varargin)
2%QBD_FI Functional Iterations for Quasi-Birth-Death Markov Chains [Neuts]
3%
4% DISCRETE TIME CASE:
5%
6% G=QBD_FI(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
9%
10% [G,R]=QBD_FI(A0,A1,A2) also provides the minimal nonnegative solution
11% to the matrix equation R = A2 + R A1 + R^2 A0
12%
13% [G,R,U]=QBD_FI(A0,A1,A2) also provides the minimal nonnegative solution
14% to the matrix equation U = A1 + A2 (I-U)^(-1) A0
15%
16% CONTINUOUS TIME CASE:
17%
18% G=QBD_FI(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
21%
22% [G,R]=QBD_FI(A0,A1,A2) also provides the minimal nonnegative solution
23% to the matrix equation 0 = A2 + R A1 + R^2 A0
24%
25% [G,R,U]=QBD_FI(A0,A1,A2) also provides the minimal nonnegative solution
26% to the matrix equation U = A1 + A2 (-U)^(-1) A0
27%
28% Optional Parameters:
29%
30% MaxNumIt: Maximum number of iterations (default: 10000)
31% Mode: 'Traditional': G(n+1) = (I-A1)^(-1) * (A0 + A2 * G^2)
32% 'Natural': G(n+1) = A0 + (A1 + A2*G(n))*G(n)
33% 'U-Based': G(n+1) = (I-A1-A2*G(n))^(-1)*A0
34% 'Shift<Mode>': where <Mode> is Traditional, Natural or
35% U-Based uses the Shift Technique
36% (default:'U-based')
37% Verbose: When set to k, the residual error is printed every
38% k steps (default:0)
39% StartValue: Starting value for iteration (default: 0)
40
41OptionNames=['Mode ';
42 'MaxNumIt ';
43 'Verbose ';
44 'StartValue '];
45OptionTypes=['char ';
46 'numeric';
47 'numeric';
48 'numeric'];
49OptionValues{1}=['Traditional ';
50 'Natural ';
51 'U-Based ';
52 'ShiftTraditional ';
53 'ShiftNatural ';
54 'ShiftU-Based ';];
55
56options=[];
57for i=1:size(OptionNames,1)
58 options.(deblank(OptionNames(i,:)))=[];
59end
60
61% Default settings
62options.Mode='U-Based';
63options.MaxNumIt=10000;
64options.Verbose=0;
65m=size(A1,1);
66options.StartValue=zeros(m,m);
67
68% Convert to discrete time problem, if needed
69m=size(A1,1);
70continues=0;
71if (sum(diag(A1)<0)) % continues time
72 continues=1;
73 lamb=max(-diag(A1));
74 A0=A0/lamb;
75 A1=A1/lamb+eye(m);
76 A2=A2/lamb;
77end
78
79% Parse Parameters
80QBD_ParsePara(A0,A1,A2);
81
82% Parse Optional Parameters
83options=ParseOptPara(options,OptionNames,OptionTypes,OptionValues,varargin);
84
85% check whether G is known explicitly
86[G,R,U]=QBD_EG(A0,A1,A2,options.Verbose,nargout);
87if (~isempty(G))
88 return
89end
90
91numit=0;
92check=1;
93G=options.StartValue;
94
95% Shift Technique
96if (strfind(options.Mode,'Shift')>0)
97 theta=statvec(A0+A1+A2);
98 drift=theta*sum(A0,2)-theta*sum(A2,2);
99 if (drift < 0) % MC is transient -> use the dual MC
100 if (nargout > 1 | options.Verbose>0)
101 A2old=A2;
102 end
103 A2=A2-ones(m,1)*(theta*A2);
104 A1=A1+ones(m,1)*(theta*A0);
105 else
106 uT=ones(1,m)/m;
107 A1old=A1;
108 if (nargout > 2 | options.Verbose>0) % store A0old to compute U
109 A0old=A0;
110 end
111 A0=A0-sum(A0,2)*uT;
112 A1=A1+sum(A2,2)*uT;
113 end
114end
115
116if (strfind(options.Mode,'Natural')>0)
117 while(check > 10^(-14) & numit < options.MaxNumIt)
118 Gold=G;
119 G=(A2*G+A1)*G+A0;
120 check=norm(G-Gold,inf);
121 numit=numit+1;
122 if (~mod(numit,options.Verbose))
123 fprintf('Check after %d iterations: %d\n',numit,check);
124 drawnow;
125 end
126 end
127end
128
129if (strfind(options.Mode,'Traditional')>0)
130 invA1=(eye(m)-A1)^(-1);
131 while(check > 10^(-14) & numit < options.MaxNumIt)
132 Gold=G;
133 G=invA1*(A0+A2*G^2);
134 check=norm(G-Gold,inf);
135 numit=numit+1;
136 if (~mod(numit,options.Verbose))
137 fprintf('Check after %d iterations: %d\n',numit,check);
138 drawnow;
139 end
140 end
141end
142
143if (strfind(options.Mode,'U-Based')>0)
144 while(check > 10^(-14) & numit < options.MaxNumIt)
145 Gold=G;
146 G=(eye(m)-A1-A2*G)^(-1)*A0;
147 check=norm(G-Gold,inf);
148 numit=numit+1;
149 if (~mod(numit,options.Verbose))
150 fprintf('Check after %d iterations: %d\n',numit,check);
151 drawnow;
152 end
153 end
154end
155if (numit == options.MaxNumIt)
156 warning('Maximum Number of Iterations %d reached',numit);
157end
158
159if (strfind(options.Mode,'Shift')>0)
160 if (drift < 0) % transient
161 if (nargout > 1 | options.Verbose >0)
162 A1=A1-ones(m,1)*theta*A0; % restore original A1
163 A2=A2old; % restore original A2
164 end
165 else % pos recurrent
166 G=G+ones(m,1)*uT;
167 if (nargout > 1 | options.Verbose >0)
168 A1=A1-sum(A2,2)*uT; % restore original A1
169 end
170 if (nargout > 2 | options.Verbose >0)
171 A0=A0old; % restore original A0
172 end
173 end
174end
175
176if (options.Verbose>0)
177 res_norm=norm(G-A0-(A1+A2*G)*G,inf);
178 fprintf('Final Residual Error for G: %d\n',res_norm);
179end
180
181% Compute R
182if (nargout > 1)
183 R=A2*(eye(m)-(A1+A2*G))^(-1);
184 if (options.Verbose>0)
185 res_norm=norm(R-A2-R*(A1+R*A0),inf);
186 fprintf('Final Residual Error for R: %d\n',res_norm);
187 end
188end
189
190% Compute U
191if (nargout > 2)
192 U=A1+R*A0;
193 if (options.Verbose>0)
194 res_norm=norm(U-A1-A2*(eye(m)-U)^(-1)*A0,inf);
195 fprintf('Final Residual Error for U: %d\n',res_norm);
196 end
197 if (continues)
198 U=lamb*(U-eye(m));
199 end
200end