home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / utils / mathstud / trace.m < prev    next >
Encoding:
Text File  |  1995-05-19  |  348 b   |  20 lines

  1. function y = trace(X)
  2. %y=trace(X)
  3. %trace Compute the trace of matrix X
  4.  
  5. %       S.Halevy 7/31/92
  6. %       Copyright (c) 1992 by the MathWizards
  7.  
  8. if nargin < 1
  9.    error('not enough arguments')
  10. end
  11. if nargin > 1
  12.    error('too many arguments')
  13. end
  14. if isvector(X)
  15.    error('trace - argument must be a matrix')
  16. end
  17.  
  18. y = sum(diag(X));
  19.  
  20.