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

  1. function [] = printsys(a,b,c,d,ulab,ylab,xlab)
  2. %PRINTSYS Print system in pretty format.
  3. %    PRINTSYS is used to print state space systems with labels to the
  4. %    right and above the system matrices or to print transfer functions
  5. %    as a ratio of two polynomials.
  6. %
  7. %    PRINTSYS(A,B,C,D,ULABELS,YLABELS,XLABELS) prints the state-space
  8. %    system with the input, output and state labels contained in the
  9. %    strings ULABELS, YLABELS, and XLABELS, respectively.  ULABELS, 
  10. %    YLABELS, and XLABELS are string variables that contain the input,
  11. %    output and state labels delimited by spaces.  For example the 
  12. %    label string
  13. %        YLABELS=['Phi Theta Psi']
  14. %    defines 'Phi' as the label for the first output, 'Theta' as the 
  15. %    label for the second output, and 'Psi' as the label for the third
  16. %     output.
  17. %    
  18. %    PRINTSYS(A,B,C,D) prints the system with numerical labels.
  19. %    
  20. %    PRINTSYS(NUM,DEN,'s') or PRINTSYS(NUM,DEN,'z') prints the transfer
  21. %    function as a ratio of two polynomials in the transform variable
  22. %    's' or 'z'.
  23. %
  24. %    See also: PRINTMAT and POLY2STR.
  25.  
  26. %    Clay M. Thompson  7-23-90
  27. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  28.  
  29. error(nargchk(2,7,nargin));
  30.  
  31. len = 12; % Label parameter.  Should match parameter in PRINTMAT.
  32.  
  33. % --- Determine which syntax is being used ---
  34. if nargin==2,        % Transfer function without transform variable
  35.   [num,den] = tfchk(a,b);
  36.   tvar = 's';
  37.  
  38. elseif nargin==3,    % Transfer function with transform variable
  39.   [num,den] = tfchk(a,b);
  40.   if ~isstr(c), error('Transform variable must be a string.'); end
  41.   tvar = c;
  42.  
  43. elseif nargin==4,    % State space system without labels
  44.   error(abcdchk(a,b,c,d));
  45.   [nx,na] = size(a);
  46.   if nx>0, 
  47.     [ny,nc] = size(c);
  48.     [nb,nu] = size(b);
  49.   else
  50.     [ny,nu] = size(d);
  51.   end
  52.   ulab = []; ylab = []; xlab = [];
  53.   for i=1:nx, xlab = [xlab, sprintf('x%-3.0f ',i)]; end
  54.   printmat(a,'a',xlab,xlab);
  55.   for i=1:nu, ulab = [ulab, sprintf('u%-3.0f ',i)]; end
  56.   printmat(b,'b',xlab,ulab);
  57.   for i=1:ny, ylab = [ylab, sprintf('y%-3.0f ',i)]; end
  58.   printmat(c,'c',ylab,xlab);
  59.   printmat(d,'d',ylab,ulab);
  60.  
  61. elseif (nargin==5)|(nargin==6),
  62.   error('Wrong number of input arguments.');
  63.  
  64. else            % State space system with labels
  65.   error(abcdchk(a,b,c,d));
  66.   [nx,na] = size(a);
  67.   [ny,nc] = size(c);
  68.   [nb,nu] = size(b);
  69.   if ~isstr(ulab), error('ULAB must be a string.'); end
  70.   if ~isstr(ylab), error('YLAB must be a string.'); end
  71.   if ~isstr(xlab), error('XLAB must be a string.'); end
  72.   
  73.   % Put labels into format for PRINTMAT
  74.   xlab = lab2str(xlab);
  75.   printmat(a,'a',xlab,xlab);
  76.   ulab = lab2str(ulab);
  77.   printmat(b,'b',xlab,ulab);
  78.   ylab = lab2str(ylab);
  79.   printmat(c,'c',ylab,xlab);
  80.   printmat(d,'d',ylab,ulab);
  81. end
  82.  
  83. if (nargin==2)|(nargin==3),    % Print system as a ratio of polynomials
  84.   [nn,mn] = size(num);
  85.  
  86.   [s,dlen] = poly2str(den,tvar);
  87.  
  88.   for i=1:nn,
  89.     [t,nlen] = poly2str(num(i,:),tvar);
  90.  
  91.     % Now print the polynomials
  92.     len=max([dlen,nlen])-3;
  93.     disp(' ')
  94.     if nn==1,
  95.       disp('num/den = ')
  96.     else
  97.       disp(['num(',int2str(i),')/den = '])
  98.     end
  99.     disp(' ')
  100.     if length(t)<len+3,        % Print numerator
  101.       disp([' '*ones(1,(len+4-length(t))/2),t]),
  102.     else
  103.       disp(t)
  104.     end
  105.     disp(['   ','-'*ones(1,len)])
  106.     if length(s)<len+3,        % Print denominator
  107.       disp([' '*ones(1,(len+4-length(s))/2),s]),
  108.     else
  109.       disp(s)
  110.     end
  111.   end
  112.  
  113. end
  114.  
  115.