2012-07-01 15:15:52 +02:00
|
|
|
|
function [X, info] = cycle_reduction(A0, A1, A2, cvg_tol, ch)
|
|
|
|
|
% function [X, info] = cycle_reduction(A0,A1,A2,A3, cvg_tolch)
|
2012-07-09 16:00:04 +02:00
|
|
|
|
%
|
|
|
|
|
% Solves Polynomial Equation:
|
2012-07-01 15:15:52 +02:00
|
|
|
|
% A0 + A1 * X + A2 * X<> = 0
|
|
|
|
|
% Using Cyclic Reduction algorithm
|
|
|
|
|
% - D.A. Bini, G. Latouche, B. Meini (2002), "Solving matrix polynomial equations arising in
|
|
|
|
|
% queueing problems", Linear Algebra and its Applications 340 (2002) 225<32>244
|
|
|
|
|
% - D.A. Bini, B. Meini, On the solution of a nonlinear matrix equation arising in queueing problems,
|
|
|
|
|
% SIAM J. Matrix Anal. Appl. 17 (1996) 906<30>926.
|
|
|
|
|
% =================================================================
|
|
|
|
|
|
2012-07-09 12:12:37 +02:00
|
|
|
|
% Copyright (C) 2012 Dynare Team
|
2012-07-01 15:15:52 +02:00
|
|
|
|
%
|
|
|
|
|
% This file is part of Dynare.
|
|
|
|
|
%
|
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
% (at your option) any later version.
|
|
|
|
|
%
|
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
|
%
|
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2012-07-09 16:00:04 +02:00
|
|
|
|
max_it = 300;
|
|
|
|
|
it = 0;
|
|
|
|
|
info = 0;
|
|
|
|
|
crit = 1+cvg_tol;
|
|
|
|
|
A_0 = A1;
|
|
|
|
|
A0_0 = A0;
|
|
|
|
|
A1_0 = A1;
|
|
|
|
|
A2_0 = A2;
|
|
|
|
|
n = length(A0);
|
|
|
|
|
id = 1:n;
|
|
|
|
|
|
|
|
|
|
while crit > cvg_tol && it < max_it;
|
2012-07-11 16:20:44 +02:00
|
|
|
|
tmp = [A2_0; A0_0]/A1_0;
|
2012-07-09 16:00:04 +02:00
|
|
|
|
TMP = tmp*A0_0;
|
2012-07-11 16:20:44 +02:00
|
|
|
|
A2_1 = - tmp(id,:)* A2_0;
|
2012-07-09 16:00:04 +02:00
|
|
|
|
A_1 = A_0 - TMP(id,:);
|
|
|
|
|
A1_1 = A1_0 - tmp(n+id,:) * A2_0 - TMP(id,:);
|
|
|
|
|
crit = sum(sum(abs(A0_0)));
|
|
|
|
|
A_0 = A_1;
|
|
|
|
|
A0_0 = -TMP(n+id,:);
|
|
|
|
|
A1_0 = A1_1;
|
|
|
|
|
A2_0 = A2_1;
|
|
|
|
|
it = it + 1;
|
|
|
|
|
end
|
2012-07-01 15:15:52 +02:00
|
|
|
|
|
2012-07-09 16:00:04 +02:00
|
|
|
|
if it==max_it
|
|
|
|
|
disp(['convergence not achieved after ' int2str(it) ' iterations']);
|
|
|
|
|
info = 1;
|
|
|
|
|
end
|
2012-07-01 15:15:52 +02:00
|
|
|
|
|
2012-07-09 16:00:04 +02:00
|
|
|
|
X = -A_0\A0;
|
2012-07-01 15:15:52 +02:00
|
|
|
|
|
2012-07-09 16:00:04 +02:00
|
|
|
|
if (nargin == 5 && ~isempty( ch ) == 1 )
|
|
|
|
|
%check the solution
|
|
|
|
|
res = A0 + A1 * X + A2 * X * X;
|
|
|
|
|
if (sum(sum(abs(res))) > cvg_tol)
|
|
|
|
|
disp(['the norm residual of the residu ' num2str(res) ' compare to the tolerance criterion ' num2str(cvg_tol)]);
|
|
|
|
|
end
|
|
|
|
|
end
|