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

  1. function S = speye(m,n)
  2. %SPEYE     Sparse identity matrix.
  3. %    SPEYE(M,N) forms an M-by-N sparse matrix with 1's on
  4. %    the main diagonal.  SPEYE(N) abbreviates SPEYE(N,N).
  5. %    SPEYE(SIZE(A)) is a space-saving SPARSE(EYE(SIZE(A))).
  6.  
  7. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  8.  
  9. if nargin < 2
  10.    if length(m) == 1
  11.       n = m;
  12.    elseif length(m) == 2
  13.       n = m(2);
  14.       m = m(1);
  15.    else 
  16.       error('Please use SPEYE(N), SPEYE(M,N) or SPEYE([M,N]).')
  17.    end
  18. end
  19. k = 1:round(min(m,n));
  20. S = sparse(k,k,1,m,n);
  21.