Skip to content

Commit

Permalink
Set niter = -1 in snorm if no convergence (like in lsedc); simplify. …
Browse files Browse the repository at this point in the history
…Improve lsedc doc.
  • Loading branch information
klho committed Jun 13, 2020
1 parent 02e4ed7 commit 19baa70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions core/snorm.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
% (default: NITER_MAX = 32).
%
% [S,NITER] = SNORM(N,MV,MVA,...) also returns the number NITER of iterations
% performed.
% required for convergence. If NITER = -1, then convergence was not detected.
%
% References:
%
Expand All @@ -44,11 +44,9 @@
x = rand(n,1);
xnorm = norm(x);
s = xnorm;
niter = 0;

% main loop
while niter < niter_max
niter = niter + 1;
for niter = 1:niter_max
x = x/xnorm;
s_ = s;

Expand All @@ -68,6 +66,7 @@
if abs(s - s_) <= s_*tol, return; end % within tolerance
end

% loop didn't return; maximum number of iterations reached
% loop didn't return; no convergence
niter = -1;
warning('FLAM:snorm:maxIterCount','Maximum number of iterations reached.')
end
14 changes: 7 additions & 7 deletions misc/lsedc.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
% [X,CRES] = LSEDC(LSFUN,A,B,C,D,TAU) also returns the constraint residual
% matrix CRES upon termination.
%
% [X,CRES,NITER] = LSEDC(LSFUN,A,B,C,D,TAU) further returns the number NITER
% of deferred correction iterations required for convergence. If NITER = -1,
% then convergence was not detected.
%
% [X,CRES,NITER] = LSEDC(LSFUN,A,B,C,D,TAU,TOL) iterates until the constraint
% [X,CRES] = LSEDC(LSFUN,A,B,C,D,TAU,TOL) iterates until the constraint
% residual matrix has norm less than or equal to TOL (default: TOL = 1E-12).
%
% [X,CRES,NITER] = LSEDC(LSFUN,A,B,C,D,TAU,TOL,NITER_MAX) uses at most
% NITER_MAX iterations (default: NITER_MAX = 8).
% [X,CRES] = LSEDC(LSFUN,A,B,C,D,TAU,TOL,NITER_MAX) uses at most NITER_MAX
% iterations (default: NITER_MAX = 8).
%
% [X,CRES,NITER] = LSEDC(LSFUN,A,B,C,D,TAU,...) further returns the number
% NITER of iterations required for convergence. If NITER = -1, then
% convergence was not detected.
%
% References:
%
Expand Down

0 comments on commit 19baa70

Please sign in to comment.