home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / VTRACE.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  51 lines

  1. % function out = vtrace(mat)
  2. %
  3. %   Trace of a VARYING/CONSTANT matrix, identical
  4. %   to MATLAB's TRACE command, but works with
  5. %   VARYING matrices also.
  6. %
  7. %   See also: DET, DIAG, TRACE, VDET, and VDIAG.
  8.  
  9. function out = vtrace(mat)
  10.   if nargin == 0
  11.     disp('usage: out = vtrace(mat)')
  12.     return
  13.   end
  14.   [mtype,mrows,mcols,mnum] = minfo(mat);
  15.   [nr,nc] = size(mat);
  16.   if mrows == mcols
  17.     if mtype == 'cons'
  18.       out = trace(mat);
  19.     elseif mtype == 'vary'
  20.       omega = mat(1:mnum,nc);
  21.       npts = mnum;
  22.       nrout = 1;
  23.       ncout = 1;
  24.       out = zeros(npts+1,ncout+1);
  25.       out(npts+1,ncout+1) = inf;
  26.       out(npts+1,ncout) = npts;
  27.       out(1:npts,ncout+1) = omega;
  28.       ftop = (npts+1)*mrows;
  29.       ptop = 1:mrows:ftop;
  30.       ptopm1 = ptop(2:npts+1) - 1;
  31.       for i=1:npts
  32.         out(i,1) = trace(mat(ptop(i):ptopm1(i),1:mcols));
  33.       end
  34.     elseif mtype == 'syst'
  35.       error('VTRACE is undefined for SYSTEM matrices')
  36.       return
  37.     else
  38.       out = [];
  39.     end
  40.   else
  41.     if mtype == 'syst'
  42.       error('VTRACE is undefined for SYSTEM matrices')
  43.       return
  44.     else
  45.       error('input matrix must be square for VTRACE')
  46.       return
  47.     end
  48.   end
  49. %
  50. % Copyright MUSYN INC 1991,  All Rights Reserved
  51.