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

  1. % function out = vpinv(mat,tol)
  2. %
  3. %   Pseudo-inverse of a VARYING/CONSTANT matrix.
  4. %   Identical to MATLAB's PINV command. The default 
  5. %   value for TOL is 1e-12.
  6. %
  7. %   See also: INV, MINV, PINV, and VINV.
  8.  
  9. function out = vpinv(mat,tol)
  10.   if nargin == 0
  11.     disp('usage: out = vpinv(mat,tol)')
  12.     return
  13.   end
  14.   if nargin == 1
  15.     tol = 1e-12;
  16.   end
  17.   [mtype,mrows,mcols,mnum] = minfo(mat);
  18.   [nr,nc] = size(mat);
  19.   if mtype == 'cons'
  20.     if nargin == 1
  21.       out = pinv(mat);
  22.     else
  23.       out = pinv(mat,tol);
  24.     end
  25.   elseif mtype == 'vary'
  26.     indv = mat(1:mnum,nc);
  27.     npts = mnum;
  28.     nrout = mcols;
  29.     ncout = mrows;
  30.     out = zeros(nrout*npts+1,ncout+1);
  31.     out(nrout*npts+1,ncout+1) = inf;
  32.     out(1:mnum,ncout+1) = indv;
  33.     out(nrout*npts+1,ncout) = npts;
  34.     fftop = (npts+1)*mcols;
  35.     pptop = 1:mcols:fftop;
  36.     pptopm1 = pptop(2:npts+1) - 1;
  37.     ftop = (npts+1)*mrows;
  38.     ptop = 1:mrows:ftop;
  39.     ptopm1 = ptop(2:npts+1) - 1;
  40.     for i=1:npts
  41.       if nargin == 1
  42.         out(pptop(i):pptopm1(i),1:ncout) = ...
  43.         pinv(mat(ptop(i):ptopm1(i),1:mcols));
  44.       else
  45.         out(pptop(i):pptopm1(i),1:ncout) = ...
  46.         pinv(mat(ptop(i):ptopm1(i),1:mcols),tol);
  47.       end
  48.     end
  49.   elseif mtype == 'syst'
  50.     error(['VPINV is undefined for SYSTEM matrices']);
  51.     return
  52.   end
  53. %
  54. % Copyright MUSYN INC 1991,  All Rights Reserved
  55.