home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPARFUN.DI$ / NORMEST.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  557 b   |  24 lines

  1. function [e,cnt] = normest(S,tol)
  2. %NORMEST Estimate the 2-norm.
  3. %    NORMEST(S) is an estimate of the 2-norm of the matrix S.
  4. %    NORMEST(S,tol) uses relative error tol instead of 1.e-6.
  5. %    [nrm,cnt] = NORMEST(S) also gives the number of power iterations used.
  6.  
  7. %    C. Moler, 4-30-91/92.
  8. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  9.  
  10. if nargin < 2, tol = 1.e-6; end
  11. x = sum(abs(S))';
  12. e = norm(x);
  13. x = x/e;
  14. cnt = 0;
  15. e0 = 0;
  16. while abs(e-e0) > tol*e
  17.    e0 = e;
  18.    Sx = S*x;
  19.    e = norm(Sx);
  20.    x = S'*Sx;
  21.    x = x/norm(x);
  22.    cnt = cnt+1;
  23. end
  24.