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

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