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

  1. % function out = vinv(mat)
  2. %
  3. %   Invert a VARYING/CONSTANT matrix. Identical to
  4. %   the MATLAB command INV and works on VARYING matrices.
  5. %
  6. %   See also: INV and MINV.
  7.  
  8. function out = vinv(mat)
  9.   if nargin == 0
  10.     disp('usage: out = vinv(mat)')
  11.     return
  12.   end
  13.   [mtype,mrows,mcols,mnum] = minfo(mat);
  14.   if mrows ~= mcols
  15.     error('input matrix should be square')
  16.     return
  17.   end
  18.   [nr,nc] = size(mat);
  19.   if mtype == 'cons'
  20.     out = inv(mat);
  21.   elseif mtype == 'vary'
  22.     omega=mat(1:mnum,nc);
  23.     npts = mnum;
  24.     nrout = mrows;
  25.     ncout = nrout;
  26.     out = zeros(nrout*npts+1,ncout+1);
  27.     out(nrout*npts+1,ncout+1) = inf;
  28.     out(1:mnum,ncout+1) = omega;
  29.     out(nrout*npts+1,ncout) = npts;
  30.     ftop = (npts+1)*mrows;
  31.     ptop = 1:mrows:ftop;
  32.     ptopm1 = ptop(2:npts+1) - 1;
  33.     for i=1:npts
  34.       out(ptop(i):ptopm1(i),1:mrows) = ...
  35.         inv(mat(ptop(i):ptopm1(i),1:mcols));
  36.     end
  37.   elseif mtype == 'syst'
  38.     error(['VINV does not work on SYSTEM matrices']);
  39.     return
  40.   end
  41. %
  42. % Copyright MUSYN INC 1991,  All Rights Reserved
  43.