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

  1. function [ac,bc,cc,dc] = cloop(a,b,c,d,e,f)
  2. %CLOOP  Close unity feedback loops.    -->O-->[System]--+--->
  3. %                                         |             |
  4. %                                         +-------------+
  5. %    [Ac,Bc,Cc,Dc] = CLOOP(A,B,C,D,SIGN) produces a state-space model
  6. %    of the closed-loop system obtained by feeding all the outputs of
  7. %    the system to all the inputs.  If SIGN = 1 then positive feedback
  8. %    is used.  If SIGN = -1 then negative feedback is used.  In all 
  9. %    cases, the resulting system has all the inputs and outputs of the
  10. %    original model.
  11. %
  12. %    [Ac,Bc,Cc,Dc] = CLOOP(A,B,C,D,OUTPUTS,INPUTS) produces the closed
  13. %    loop system obtained by feeding the specified outputs into the 
  14. %    specified outputs.  The vectors OUTPUTS and INPUTS contain indexes
  15. %    into the outputs and inputs of the system respectively.  Positive
  16. %    feedback is assumed. To close with negative feedback, use negative
  17. %    values in the vector INPUTS.
  18. %
  19. %    [NUMc,DENc] = CLOOP(NUM,DEN,SIGN) produces the SISO closed loop 
  20. %    system in transfer function form obtained by unity feedback with
  21. %    the sign SIGN.
  22. %
  23. %    See also: PARALLEL, SERIES, and FEEDBACK.
  24.  
  25. %    Clay M. Thompson 6-26-90
  26. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  27.  
  28. error(nargchk(2,6,nargin));
  29.  
  30. % --- Determine which syntax is being used. ---
  31.  
  32. if (nargin == 2)   % T.F. form w/o sign -- Assume negative feedback
  33.   [num,den] = tfchk(a,b); sgn = -1;
  34. end
  35. if (nargin == 3)   % Transfer function form with sign
  36.   [num,den] = tfchk(a,b); sgn=sign(c);
  37. end
  38.  
  39. % --- Form closed loop T.F. system ---
  40. if (nargin == 2)|(nargin == 3)
  41.   ac = num; bc = den - sgn*num;
  42.  
  43. elseif (nargin >= 4)  % State space systems
  44.   error(abcdchk(a,b,c,d));
  45.   [ny,nu] = size(d);
  46.   if (nargin == 4)    % System w/o sign -- Assume negative feedback
  47.     outputs = 1:ny; inputs = [1:nu]; sgn = -ones(1,length(inputs));
  48.   end
  49.   if (nargin == 5)    % State space form with sign
  50.     outputs = 1:ny; inputs = [1:nu]; sgn = sign(e)*ones(1,length(inputs));
  51.   end
  52.   if (nargin == 6)    % State space form w/selection vectors
  53.     outputs=e; inputs=abs(f); sgn=sign(f);
  54.   end
  55.  
  56.   % --- Form Closed Loop State-space System ---
  57.  
  58.   nin = length(inputs); nout = length(outputs);
  59.   if nin ~= nout,
  60.     error('The number of feedback inputs and outputs are not equal');
  61.   end
  62.   [nx,na] = size(a);
  63.  
  64.   % Form feedback column and row, deal with nonzero D22
  65.   S = [a,b;c,d];
  66.   Bu = S(:,[nx+inputs]); Cy = S([nx+outputs],:);
  67.   if ~isempty(Cy)
  68.     Cy(sgn==-1,:)=-Cy(sgn==-1,:);  % Get ready for negative feedback
  69.     E = eye(nout) - Cy(:,[nx+inputs]);    % E=(I-D22)
  70.     Cy = E\Cy;
  71.     
  72.     Sc = S + Bu*Cy;   % Close Loop
  73.  
  74.     % Extract closed loop system
  75.     ac = Sc(1:nx, 1:nx);
  76.     bc = Sc(1:nx, nx+1:nx+nu);
  77.     cc = Sc(nx+1:nx+ny, 1:nx);
  78.     dc = Sc(nx+1:nx+ny, nx+1:nx+nu);
  79.   else
  80.     ac=a; bc=b; cc=c; dc=d;
  81.   end
  82. end
  83.