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

  1. function y = cond(x)
  2. %COND    Matrix condition number.
  3. %    COND(X) is the ratio of the largest singular value of X
  4. %    to the smallest, which is the condition number of X in 2-norm.
  5. %
  6. %    See also RCOND, NORM, CONDEST, NORMEST.
  7.  
  8. %    J.N. Little 11-15-85
  9. %    Revised 3-9-87 JNL, 2-11-92 LS.
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. if length(x) == 0  % Handle null matrix
  13.     y = NaN;
  14.     return
  15. end
  16. if issparse(x)
  17.     error('Matrix must be non-sparse.')
  18. end
  19. s = svd(x);
  20. if any(s == 0)   % Handle singular matrix
  21.     disp('Condition is infinite')
  22.     y = Inf;
  23.     return
  24. end
  25. y = max(s)./min(s);
  26.