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

  1. function [k,poles] = rlocfind(a,b,c,d,p)
  2. %RLOCFIND Find the root locus gains for a given set of roots.
  3. %    [K,POLES] = RLOCFIND(A,B,C,D) puts up a crosshair cursor in the 
  4. %    graphics window which is used to select a pole location on an 
  5. %    existing root locus.  The root locus gain associated with this 
  6. %    point is returned in K and all the system poles for this gain are
  7. %    returned in POLES.  To use this command, the root locus for the 
  8. %    SISO state-space system (A,B,C,D) must be present in the graphics
  9. %    window.  If the system is MIMO, an error message is produced.  
  10. %    RLOCFIND works with both continuous and discrete linear systems.
  11. %
  12. %    [K,POLES] = RLOCFIND(NUM,DEN) is used to select a point on the 
  13. %    root locus of the polynomial system G = NUM/DEN where NUM and DEN 
  14. %    are polynomials in descending powers of s or z.
  15. %
  16. %    When invoked with an additional right hand argument,
  17. %        [K,POLES] = RLOCFIND(A,B,C,D,P)
  18. %        [K,POLES] = RLOCFIND(NUM,DEN,P)
  19. %    returns a vector K of gains and the matrix of associated poles, 
  20. %    POLES. The vector K contains one element for each desired root 
  21. %    location in P.  The matrix POLES contains one column for each 
  22. %    root location in P and (LENGTH(DEN)-1) or LENGTH(A) rows.
  23. %
  24. %    See also: RLOCUS.
  25.  
  26. %    Clay M. Thompson  7-16-90
  27. %    Revised ACWG 8-14-91, 6-21-92
  28. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  29.  
  30. error(nargchk(2,5,nargin));
  31.  
  32. % --- Determine which syntax is being used ---
  33. if (nargin==2),        % Transfer function without poles
  34.     [num,den] = tfchk(a,b);
  35.     % Normalize transfer function
  36.     num = num/den(1);
  37.     den = den/den(1);
  38.     [ny,nn] = size(num);
  39.     if (ny~=1), error('RLOCFIND must be used with SISO systems.'); end
  40.     disp('Select a point in the graphics window')
  41.     [re,im] = ginput(1);    % Get one point
  42.     p = re + sqrt(-1)*im;
  43.  
  44. elseif (nargin==3),    % Transfer function with poles
  45.     [num,den] = tfchk(a,b);
  46.     [ny,nn] = size(num);
  47.     if (ny~=1), error('RLOCFIND must be used with SISO systems.'); end
  48.     p=c;
  49.  
  50. elseif (nargin==4),    % State space system without poles
  51.     error(abcdchk(a,b,c,d));
  52.     [ny,nu] = size(d);
  53.     if (ny*nu~=1), error('RLOCFIND must be used with SISO systems.'); end
  54.     [num,den] = ss2tf(a,b,c,d);
  55.     disp('Select a point in the graphics window')
  56.     [re,im] = ginput(1);    % Get one point
  57.     p = re + sqrt(-1)*im;
  58.  
  59. else,            % State space system with poles
  60.     error(abcdchk(a,b,c,d));
  61.     [ny,nu] = size(d);
  62.     if (ny*nu~=1), error('RLOCFIND must be used with SISO systems.'); end
  63.     [num,den] = ss2tf(a,b,c,d);
  64.  
  65. end
  66.  
  67. % Use root locus magnitude rule to determine gain value.  Assume the
  68. % root locus is based on negative feedback.
  69.  
  70. z = roots(num); 
  71. e = roots(den);
  72. [ny,ns] = size(num);
  73. for i=1:ny,
  74.     tfgain(i) = num(i,min(find(abs(num(i,:))>eps)));
  75. end
  76. p = p(:);    % Make sure desired roots are a column
  77.  
  78. np=length(p); ne = length(e); nz = length(z);
  79. k = prod(abs(ones(ne,1)*p.'-e*ones(1,np))) ./ prod(abs(ones(nz,1)*p'-z*ones(1,np))) ./ tfgain;
  80. k = abs(k);
  81.  
  82. % Determine all the poles for each gain.
  83. for i=1:length(k),
  84.     if ~finite(k(i)),
  85.         poles(:,i)=roots(num);
  86.     else
  87.         poles(:,i)=roots(den+k(i)*num);
  88.     end
  89. end
  90.  
  91. % If selecting points from root locus, plot all the roots
  92. if (nargin==2)|(nargin==4),
  93.     status = ishold;
  94.     hold on
  95.     plot(real(poles),imag(poles),'w+')
  96.     if ~status, hold off, end
  97.     selected_point = p    % Feedback to user
  98. end
  99.  
  100.  
  101.