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

  1. % function  out = vrdiv(mat1,mat2)
  2. %
  3. %   Right division for VARYING/CONSTANT matrices.
  4. %   Identical to the MATLAB / command, but works
  5. %   on VARYING matrices as well MAT1/MAT2.
  6. %
  7. %   See also: \, /, INV, MINV, PINV, VINV, VLDIV and VPINV.
  8.  
  9. function out = vrdiv(mat1,mat2)
  10.   if nargin ~= 2
  11.     disp('usage: out = vrdiv(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(['VRDIV is not defined for SYSTEM matrices']);
  19.     return
  20.   end
  21.   if strcmp(mtype2,'syst')
  22.     error(['VRDIV is not defined for SYSTEM matrices']);
  23.     return
  24.   end
  25.   if strcmp(mtype1,'vary')
  26.     varyflg = 1;
  27.   end
  28.   if mcols1 ~= mcols2
  29.     error(['input matrices to VRDIV must have same number of columns']);
  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 = mrows1;
  44.   ncout = mrows2;
  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.       ftwo = (npts+1)*mrows2;
  87.       ptwo = 1:mrows2:ftwo;
  88.       ptwom1 = ptwo(2:npts+1) - 1;
  89.       for i=1:npts
  90.        out((i-1)*nrout+1:nrout*i,1:ncout) = ...
  91.        mat1(pone(i):ponem1(i),1:mcols1)/mat2(ptwo(i):ptwom1(i),1:mcols2);
  92.       end
  93.     end
  94.   end
  95. %
  96. % Copyright MUSYN INC 1991,  All Rights Reserved
  97.