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

  1. % function out = abv(mat1,mat2,mat3...,matN)
  2. %
  3. %   Stacks VARYING/SYSTEM/CONSTANT matrices above one another:
  4. %
  5. %                          |  mat1  |
  6. %                          |  mat2  |
  7. %            out    =      |  mat3  |
  8. %                          |   ..   |
  9. %                          |  matN  |
  10. %
  11. %   See also: MADD, DAUG, MMULT, SBS, SEL, and VDIAG.
  12.  
  13. function out = abv(mat1,mat2,mat3,mat4,mat5,mat6,mat7,mat8,mat9)
  14.  if nargin < 2
  15.    disp('usage: out = abv(mat1,mat2,mat3,...,matN)')
  16.    return
  17.  elseif nargin == 2
  18.    top = mat1;
  19.    bot = mat2;
  20.    if isempty(top)
  21.      out = bot;
  22.    elseif isempty(bot)
  23.      out = top;
  24.    else
  25.      [toptype,toprows,topcols,topnum] = minfo(top);
  26.      [bottype,botrows,botcols,botnum] = minfo(bot);
  27.      if (bottype == 'syst' & toptype == 'vary') | ...
  28.                 (bottype == 'vary' & toptype == 'syst')
  29.        error('ABV of SYSTEM and VARYING not allowed')
  30.        return
  31.      end
  32.      if topcols ~= botcols
  33.        error('incompatible column (input) dimensions')
  34.        return
  35.      end
  36.      if toptype == 'vary'
  37.        if bottype == 'vary'
  38. %     both VARYING
  39.          code = indvcmp(top,bot);
  40.          if code == 1
  41.            [vdt,rpt,indvt] = vunpck(top);
  42.            [vdb,rpb,indvb] = vunpck(bot);
  43.            tmp = [reshape(vdt,toprows,topnum*topcols);...
  44.                  reshape(vdb,botrows,botnum*botcols)];
  45.        out = zeros((toprows+botrows)*topnum+1,topcols+1);
  46.        out((toprows+botrows)*topnum+1,topcols+1) = inf;
  47.        out((toprows+botrows)*topnum+1,topcols) = topnum;
  48.         out(1:topnum,topcols+1) = indvt;
  49.        out(1:(toprows+botrows)*topnum,1:topcols) = ...
  50.                  reshape(tmp,topnum*(toprows+botrows),topcols);
  51.          else
  52.            error('varying data is inconsistent')
  53.            return
  54.          end
  55.        else
  56. %     VARYING above CONSTANT
  57.          [vdt,rpt,indvt] = vunpck(top);
  58.          tmp = [reshape(vdt,toprows,topnum*topcols);...
  59.                kron(bot,ones(1,topnum))];
  60.      out = zeros((toprows+botrows)*topnum+1,topcols+1);
  61.      out((toprows+botrows)*topnum+1,topcols+1) = inf;
  62.      out((toprows+botrows)*topnum+1,topcols) = topnum;
  63.      out(1:topnum,topcols+1) = indvt;
  64.      out(1:(toprows+botrows)*topnum,1:topcols) = ...
  65.                reshape(tmp,topnum*(toprows+botrows),topcols);
  66.        end
  67.      elseif toptype == 'cons'
  68.        if bottype == 'vary'
  69.          [vdb,rpb,indvb] = vunpck(bot);
  70.          tmp = [kron(top,ones(1,botnum));...
  71.                reshape(vdb,botrows,botnum*topcols)];
  72.      out = zeros((toprows+botrows)*botnum+1,topcols+1);
  73.      out((toprows+botrows)*botnum+1,topcols+1) = inf;
  74.      out((toprows+botrows)*botnum+1,topcols) = botnum;
  75.      out(1:botnum,topcols+1) = indvb;
  76.      out(1:(toprows+botrows)*botnum,1:topcols) = ...
  77.                reshape(tmp,botnum*(toprows+botrows),topcols);
  78.        elseif bottype == 'cons'
  79.          out = [top ; bot];
  80.        else
  81.          [a,b,c,d] = unpck(bot);
  82.          cc = [zeros(toprows,botnum) ; c];
  83.          dd = [top ; d];
  84.          out = pck(a,b,cc,dd);
  85.        end
  86.      else
  87.        if bottype == 'cons'
  88.          [a,b,c,d] = unpck(top);
  89.          cc = [c ; zeros(botrows,topnum)];
  90.          dd = [d ; bot];
  91.          out = pck(a,b,cc,dd);
  92.        else
  93.          [at,bt,ct,dt] = unpck(top);
  94.          [ab,bb,cb,db] = unpck(bot);
  95.          a = daug(at,ab);
  96.          b = [bt ; bb];
  97.          c = [ct zeros(toprows,botnum) ; zeros(botrows,topnum) cb];
  98.          d = [dt;db];
  99.          out = pck(a,b,c,d);
  100.        end
  101.      end
  102.    end
  103.  else
  104. %  recursive call for more than two input arguments
  105.    exp = ['out=abv(abv('];
  106.    for i=1:nargin-2
  107.      exp=[exp 'mat' int2str(i) ','];
  108.    end
  109.    exp = [exp 'mat' int2str(nargin-1) '),mat' int2str(nargin) ');'];
  110.    eval(exp);
  111.  end
  112. %
  113. % Copyright MUSYN INC 1991,  All Rights Reserved
  114.