cycle reduction: return error codes for over- and under-determined

dynamic systems
time-shift
Michel Juillard 2012-07-22 12:51:55 +02:00
parent edf826f315
commit 2c450c79f8
1 changed files with 33 additions and 23 deletions

View File

@ -63,38 +63,48 @@ function [X, info] = cycle_reduction(A0, A1, A2, cvg_tol, ch)
max_it = 300; max_it = 300;
it = 0; it = 0;
info = 0; info = 0;
crit = 1+cvg_tol; X = [];
A_0 = A1; crit = Inf;
A0_0 = A0; A0_0 = A0;
A1_0 = A1; if (nargin == 5 && ~isempty(ch) )
A2_0 = A2; A1_0 = A1;
A2_0 = A2;
end
n = length(A0); n = length(A0);
id = 1:n; id0 = 1:n;
id2 = id0+n;
while crit > cvg_tol && it < max_it; cont = 1;
tmp = [A2_0; A0_0]/A1_0; while cont
TMP = tmp*A0_0; crit > cvg_tol && it < max_it && ~isnan(crit)
A2_1 = - tmp(id,:)* A2_0; tmp = ([A0; A2]/A1)*[A0 A2];
A_1 = A_0 - TMP(id,:); A1 = A1 - tmp(id0,id2) - tmp(id2,id0);
A1_1 = A1_0 - tmp(n+id,:) * A2_0 - TMP(id,:); A0 = -tmp(id0,id0);
crit = sum(sum(abs(A0_0))); A2 = -tmp(id2,id2);
A_0 = A_1; crit = norm(A0,1);
A0_0 = -TMP(n+id,:); if crit < cvg_tol
A1_0 = A1_1; % keep iterating until condition on A2 is met
A2_0 = A2_1; if norm(A2,1) < cvg_tol
cont = 0;
end
elseif isnan(crit) || it == max_it
if crit < cvg_tol
info(1) = 4;
info(2) = log(norm(A2,1))
else
info(1) = 3;
info(2) = log(norm(A1,1))
end
return
end
it = it + 1; it = it + 1;
end end
if it==max_it X = -A1\A0_0;
disp(['convergence not achieved after ' int2str(it) ' iterations']);
info = 1;
end
X = -A_0\A0;
if (nargin == 5 && ~isempty(ch) ) if (nargin == 5 && ~isempty(ch) )
%check the solution %check the solution
res = A0 + A1 * X + A2 * X * X; res = A0_0 + A1_0 * X + A2_0 * X * X;
if (sum(sum(abs(res))) > cvg_tol) if (sum(sum(abs(res))) > cvg_tol)
disp(['the norm residual of the residu ' num2str(res) ' compare to the tolerance criterion ' num2str(cvg_tol)]); disp(['the norm residual of the residu ' num2str(res) ' compare to the tolerance criterion ' num2str(cvg_tol)]);
end end