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

  1. % function [u,s,v] = vsvd(mat)
  2. %
  3. %   Singular value decomposition of a VARYING/CONSTANT
  4. %   matrix, identical to MATLAB's SVD command, but
  5. %   VSVD works with VARYING matrices also.
  6. %
  7. %   See also: COND, EIG, SVD, VCOND, VEIG, and VNORM.
  8.  
  9. function [out1,out2,out3] = vsvd(mat)
  10.   if nargin ~= 1
  11.     disp(['usage: [u,s,v] = vsvd(mat)'])
  12.     return
  13.   end
  14.   if nargout == 2
  15.     error(['incorrect number of output arguments']);
  16.     return
  17.   end
  18.   [mtype,mrows,mcols,mnum] = minfo(mat);
  19.   if mtype == 'cons'
  20.     if nargout <= 1
  21.       out1 = svd(mat);
  22.     else
  23.       [out1,out2,out3] = svd(mat);
  24.     end
  25.   elseif mtype == 'vary'
  26.     indv = mat(1:mnum,mcols+1);
  27.     if nargout <= 1
  28.       npts = mnum;
  29.       nrout = min([mrows mcols]);
  30.       ncout = 1;
  31.       out = zeros((nrout*npts)+1,ncout+1);
  32.       out1((nrout*npts)+1,ncout+1) = inf;
  33.       out1((nrout*npts)+1,ncout) = npts;
  34.       out1(1:npts,ncout+1) = indv;
  35.       for i=1:npts
  36.         out1((i-1)*nrout+1:i*nrout,1:ncout) = ...
  37.              svd(mat((i-1)*mrows+1:i*mrows,1:mcols));
  38.       end
  39.     else
  40.       npts = mnum;
  41.       nrout1 = mrows; ncout1 = mrows;
  42.       nrout2 = mrows; ncout2 = mcols;
  43.       nrout3 = mcols; ncout3 = mcols;
  44.       out1 = zeros(nrout1*npts,ncout1);
  45.       out2 = zeros(nrout2*npts,ncout2);
  46.       out3 = zeros(nrout3*npts,ncout3);
  47.       out1((nrout1*npts)+1,ncout1+1) = inf;
  48.       out1((nrout1*npts)+1,ncout1) = npts;
  49.       out1(1:npts,ncout1+1) = indv;
  50.       out2((nrout2*npts)+1,ncout2+1) = inf;
  51.       out2((nrout2*npts)+1,ncout2) = npts;
  52.       out2(1:npts,ncout2+1) = indv;
  53.       out3((nrout3*npts)+1,ncout3+1) = inf;
  54.       out3((nrout3*npts)+1,ncout3) = npts;
  55.       out3(1:npts,ncout3+1) = indv;
  56.       for i=1:npts
  57.         [tu,ts,tv] = svd(mat((i-1)*mrows+1:i*mrows,1:mcols));
  58.         out1((i-1)*nrout1+1:i*nrout1,1:ncout1) = tu;
  59.         out2((i-1)*nrout2+1:i*nrout2,1:ncout2) = ts;
  60.         out3((i-1)*nrout3+1:i*nrout3,1:ncout3) = tv;
  61.       end
  62.     end
  63.   elseif mtype == 'syst'
  64.     error('VSVD is undefined for SYSTEM matrices')
  65.     return
  66.   end
  67. %
  68. % Copyright MUSYN INC 1991,  All Rights Reserved
  69.