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

  1. % function  out = vldiv(mat1,mat2)
  2. %
  3. %   Left division for VARYING/CONSTANT matrices. Identical 
  4. %   to the MATLAB \ command, but works on VARYING matrices 
  5. %   as well. MAT1\MAT2
  6. %
  7. %   See also: \, /, INV, MINV, VINV, and VRDIV.
  8.  
  9. function out = vldiv(mat1,mat2)
  10.   if nargin ~= 2
  11.     disp('usage: out = vldiv(mat1,mat2)')
  12.     return
  13.   end
  14.   varyflg = 0;
  15.   [mtype1,mrows1,mcols1,mnum1] = minfo(mat1);
  16.   [mtype2,mrows2,mcols2,mnum2] = minfo(mat2);
  17.   if strcmp(mtype1,'syst')
  18.     error(['VLDIV is not defined for SYSTEM matrices']);
  19.     return
  20.   end
  21.   if strcmp(mtype2,'syst')
  22.     error(['VLDIV is not defined for SYSTEM matrices']);
  23.     return
  24.   end
  25.   if strcmp(mtype1,'vary')
  26.     varyflg = 1;
  27.   end
  28.   if mrows1 ~= mrows2
  29.     error(['input matrices to VLDIV must have same number of rows']);
  30.     return
  31.   end
  32.   if strcmp(mtype2,'vary')
  33.     if varyflg == 1
  34.       code = indvcmp(mat1,mat2);
  35.       if code ~= 1
  36.          error(['inconsistent varying data'])
  37.          return
  38.       end
  39.     else
  40.       varyflg = 1;
  41.     end
  42.   end
  43.   nrout = mcols1;
  44.   ncout = mcols2;
  45.   if strcmp(mtype1,'cons')
  46.     if strcmp(mtype2,'cons')
  47.       out = mat1\mat2;
  48.     else                % m2 is VARYING
  49.       indv = mat2(1:mnum2,mcols2+1);
  50.       npts = mnum2;
  51.       out = zeros(npts*nrout+1,ncout+1);
  52.       out(npts*nrout+1,ncout+1) = inf;
  53.       out(npts*nrout+1,ncout) = npts;
  54.       out(1:npts,ncout+1) = indv;
  55.       fone = (npts+1)*mrows2;
  56.       pone = 1:mrows2:fone;
  57.       ponem1 = pone(2:npts+1) - 1;
  58.       for i=1:npts
  59.          out((i-1)*nrout+1:nrout*i,1:ncout) = ...
  60.          mat1\mat2(pone(i):ponem1(i),1:mcols2);
  61.       end
  62.     end
  63.   else  % m1 is varying
  64.     npts = mnum1;
  65.     indv = mat1(1:mnum1,mcols1+1);
  66.     if strcmp(mtype2,'cons')
  67.       out = zeros(npts*nrout+1,ncout+1);
  68.       out(npts*nrout+1,ncout+1) = inf;
  69.       out(npts*nrout+1,ncout) = npts;
  70.       out(1:npts,ncout+1) = indv;
  71.       fone = (npts+1)*mrows1;
  72.       pone = 1:mrows1:fone;
  73.       ponem1 = pone(2:npts+1) - 1;
  74.       for i=1:npts
  75.         out((i-1)*nrout+1:nrout*i,1:ncout) = ...
  76.         mat1(pone(i):ponem1(i),1:mcols1)\mat2;
  77.       end
  78.     else
  79.       out = zeros(npts*nrout+1,ncout+1);
  80.       out(npts*nrout+1,ncout+1) = inf;
  81.       out(npts*nrout+1,ncout) = npts;
  82.       out(1:npts,ncout+1) = indv;
  83.       fone = (npts+1)*mrows1;
  84.       pone = 1:mrows1:fone;
  85.       ponem1 = pone(2:npts+1) - 1;
  86.       for i=1:npts
  87.        out((i-1)*nrout+1:nrout*i,1:ncout) = ...
  88.        mat1(pone(i):ponem1(i),1:mcols1)\mat2(pone(i):ponem1(i),1:mcols2);
  89.       end
  90.     end
  91.   end
  92. %
  93. % Copyright MUSYN INC 1991,  All Rights Reserved
  94.