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

  1. function [aa,bb,cc,dd] = connect(a,b,c,d,q,iu,iy)
  2. %CONNECT  Given the block diagram of a system, CONNECT can be used to
  3. %    form an (A,B,C,D) state-space model of the system.
  4. %
  5. %    [Ac,Bc,Cc,Dc] = CONNECT(A,B,C,D,Q,INPUTS,OUTPUTS)  returns the 
  6. %    state-space matrices (Ac,Bc,Cc,Dc) of a system given the block 
  7. %    diagonal, unconnected (A,B,C,D) matrices and a matrix Q that 
  8. %    specifies the interconnections.  The matrix Q has a row for each 
  9. %    input, where the first element of each row is the number of the 
  10. %    input.  The subsequent elements of each row specify where the 
  11. %    block gets its summing inputs, with negative elements used to 
  12. %    indicate minus inputs to the summing junction.  For example, if 
  13. %    block 7 gets its inputs from the outputs of blocks 2, 15, and 6, 
  14. %    and the block 15 input is negative, the 7'th row of Q would be 
  15. %    [7 2 -15 6].  The vectors INPUTS and OUTPUTS are used to select 
  16. %    the final inputs and outputs for (Ac,Bc,Cc,Dc). 
  17. %
  18. %    For more information see the User's Guide.   
  19. %    See also BLKBUILD and CLOOP.
  20.  
  21. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  22. %     J.N. Little 7-24-85
  23. %     Last modified JNL 6-2-86
  24.  
  25. [mq,nq] = size(q);
  26. [md,nd] = size(d); 
  27.  
  28. % Form k from q, the feedback matrix such that u = k*y forms the
  29. % desired connected system.  k is a matrix of zeros and plus or minus ones.
  30.  
  31. k = zeros(nd,md);
  32. % Go through rows of Q
  33. for i=1:mq
  34.     % Remove zero elements from each row of Q
  35.     qi = q(i,find(q(i,:)));
  36.     [m,n] = size(qi);
  37.     % Put the zeros and +-ones in K
  38.     if n ~= 1
  39.         k(qi(1),abs(qi(2:n))) = sign(qi(2:n));
  40.     end
  41. end
  42.  
  43. % Use output feedback to form closed loop system
  44. %    .
  45. %    x = Ax + Bu
  46. %    y = Cx + Du      where  u = k*y + Ur 
  47. %
  48. bb = b/(eye(nd) - k*d);
  49. aa = a + bb*k*c;
  50. t = eye(md) - d*k;
  51. cc = t\c;
  52. dd = t\d;
  53.  
  54. % Select just the outputs and inputs wanted:
  55. bb = bb(:,iu);
  56. cc = cc(iy,:);
  57. dd = dd(iy,iu);
  58.