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

  1. %BLKBUILD Builds a block diagonal state space structure from a block 
  2. %       diagram of transfer functions and state models.  This is a 
  3. %       SCRIPT FILE.
  4. %
  5. %INPUTS:
  6. %  nblocks      is the number of blocks in the diagram.
  7. %
  8. %  ni and di    are the numerator and denominator polynomials for 
  9. %               the ith block if it is a transfer function.
  10. %
  11. %  ai,bi,ci,di  are the state matrices for the ith block if it is a
  12. %               state model.
  13. %
  14. %OUTPUTS:
  15. %  a,b,c,d      is the resulting state space structure. The matrices
  16. %               are built up by progressive APPENDs of the state 
  17. %               space representations of each block.
  18. %
  19. %    Note: If both ni,di and ai,bi,ci,di exist for the same block then
  20. %    an error is generated.
  21. %
  22. %    See also: CONNECT.
  23.  
  24. %    Clay M. Thompson
  25. %    Revised by Wes Wang 8-5-92
  26. %    Copyright (c) 1986-93 by The MathWorks, Inc.
  27.  
  28. if exist('a1') & exist('b1') & exist('c1')
  29.   if exist('n1') & exist('d1')
  30.     error('Both state space and transfer function forms for block 1 exist.')
  31.   end
  32.   a=a1; b=b1; c=c1;
  33.   if exist('d1')
  34.     d = d1;
  35.   else
  36.     [ii9,mm9]=size(b1);
  37.     [pp9,ii9]=size(c1);
  38.     d = zeros(pp9,mm9);
  39.   end
  40. elseif exist('n1')
  41.   [a,b,c,d]=tf2ss(n1,d1);
  42. else
  43.   error('Block 1 is not defined.');
  44. end
  45.     
  46. for ibb9=2:nblocks
  47.    xxist = int2str(ibb9);
  48.    if exist(['a' xxist]) & exist(['b' xxist]) & exist(['c' xxist])
  49.      % if ai,bi,ci,di exist
  50.      if exist(['n' xxist]) & exist(['d' xxist])
  51.        error(['Both state space and transfer function forms for block ', ...
  52.              xxist,' exist.']);
  53.      end
  54.      smstr = [ 'a' xxist ',b' xxist ',c' xxist ];
  55.      if exist(['d' xxist])
  56.        dd9 = eval(['d' xxist]);
  57.      else
  58.        [ii9,mm9]=size(eval(['b' xxist']));
  59.        [pp9,ii9]=size(eval(['c' xxist']));
  60.        dd9 = zeros(pp9,mm9);
  61.      end
  62.      eval([ '[a,b,c,d] = append(a,b,c,d,' smstr ',dd9);']);
  63.    elseif exist(['n' xxist]) & exist(['d' xxist])
  64.      ii9 = int2str(ibb9);         % Convert ibb9 to string representation
  65.      [aa9,bb9,cc9,dd9] = eval(['tf2ss(n',ii9,',d',ii9,')']);
  66.      [a,b,c,d] = append(a,b,c,d,aa9,bb9,cc9,dd9);
  67.    else
  68.      error(['Block ' xxist ' is not defined.']);
  69.    end
  70. end
  71.  
  72. [pp9,mm9]=size(d);
  73. disp(['State model [a,b,c,d] of the block diagram has ',int2str(mm9), ...
  74.       ' inputs and ',int2str(pp9),' outputs'])
  75.  
  76. clear aa9 bb9 cc9 dd9 ii9 ibb9 xxist smstr pp9 mm9
  77.