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

  1. % function out = minv(mat)
  2. %
  3. %   Invert a SYSTEM/VARYING/CONSTANT matrix.
  4. %
  5. %   See also: INV, VDET, and VINV.
  6.  
  7. function out = minv(mat)
  8.   if nargin == 0
  9.     disp('usage: out = minv(mat)')
  10.     return
  11.   end
  12.   [mtype,mrows,mcols,mnum] = minfo(mat);
  13.   if mrows ~= mcols
  14.     error('input matrix should be square')
  15.     return
  16.   end
  17.   if mtype == 'cons'
  18.     out = inv(mat);
  19.   elseif mtype == 'vary'
  20.     if mrows == 1    % fast for     1 x 1    VARYING matrices
  21.       out = mat;
  22.       out(1:mnum,1) = ones(mnum,1)./mat(1:mnum,1);
  23.     else
  24.       omega = mat(1:mnum,mcols+1);
  25.       npts = mnum;
  26.       nrout = mrows;
  27.       ncout = nrout;
  28.       out = zeros(nrout*npts+1,ncout+1);
  29.       out(nrout*npts+1,ncout+1) = inf;
  30.       out(1:mnum,ncout+1) = omega;
  31.       out(nrout*npts+1,ncout) = npts;
  32.       ftop = (npts+1)*mrows;
  33.       ptop = 1:mrows:ftop;
  34.       ptopm1 = ptop(2:npts+1) - 1;
  35.       for i=1:npts
  36.         out(ptop(i):ptopm1(i),1:mrows) = ...
  37.           inv(mat(ptop(i):ptopm1(i),1:mcols));
  38.       end
  39.     end
  40.   elseif mtype == 'syst'
  41.     [a,b,c,d] = unpck(mat);
  42.     bdi = b / d;
  43.     di = inv(d);
  44.     dic = d \ c;
  45.     out = pck(a-b*dic,-bdi,dic,di);
  46.   end
  47.  
  48. %
  49. % Copyright MUSYN INC 1991,  All Rights Reserved
  50.