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

  1. function [v,n]=vrsys(s)
  2. % [VARS,N] = VRSYS(NAME) returns string VARS and an integer N where VARS
  3. %      contains the list of N variable names associated with a system
  4. %      having system name NAME.  A valid system name is a string of the form
  5. %             NAME = [TY '_' SUF]
  6. %      where SUF is a suffix string which is appended to standard
  7. %      variable names in a list determined by the string TY as follows:
  8. % -----   -------------------------------  ---------------------------
  9. % TY      VAR prior to appending suffixes  Description
  10. % -----   -------------------------------  ---------------------------
  11. % 'ss'    'a,b,c,d'                        Standard Statespace (default)
  12. % 'des'   'a,b,c,d,e'                      Descriptor System
  13. % 'tss'   'a,b1,b2,c1,c2,d11,d12,d21,d22'  Two-port Statespace 
  14. % 'tdes'  'a,b1,b2,c1,c2,d11,d12,d21,d22,e'Two-port Descriptor
  15. % 'gsm'   'sm,dimx,dimu,dimy'              General statespace
  16. % 'gdes'  'e,sm,dimx,dimu,dimy'            General descriptor
  17. % 'gpsm'  'psm,deg,dimx,dimu,dimy'         General polynom. sys. matrix
  18. % 'tf'    'num,den'                        Transfer function
  19. % 'tfm'   'num,den,n,m'                    Transfer function matrix
  20. % 'sm'    'sm,dim'                         State-space system matrix
  21. % 'tsm'   'tsm,dim'                        Two-port state-space sys. mat.
  22. % 'imp'   'y,ts,nu,ny'                     Impulse response
  23. % ----------------------------------------------------------------------
  24. % A capital TY string returns the string VAR as above, but in capitals. 
  25.  
  26. % R. Y. Chiang & M. G. Safonov 10/25/90    
  27. % Copyright (c) 1990 by the MathWorks, Inc.
  28. % All Rights Reserved.
  29. % ---------------------------------------------------------------------------
  30.  
  31. if nargin==0,s1='ss_';nargin=1;end  % Default
  32. nin =nargin;
  33.    % Remove any spaces
  34.    ind=find(s==' ');
  35.    if max(size(ind))>0,
  36.       s(ind)='';
  37.    end
  38.  
  39.    % Get SUF and TY
  40.    s = ['_' s '_'];
  41.    ind=find(s=='_');
  42.    [rind,cind]=size(ind);
  43.    if ind(2)-ind(1)>1,
  44.        ty = s(ind(1)+1:ind(2)-1);
  45.    else
  46.        ty ='ss';
  47.    end
  48.    if cind==2,
  49.       suf = '';
  50.    else
  51.       suf = s(ind(2)+1:ind(3)-1);
  52.    end
  53.    
  54.    if max(size(ty))==0, ty='ss',end
  55.  
  56.    ty1=ty;
  57.  
  58.    % if ty is capital, set CAPFLAG and convert to lowercase
  59.    if ty(1)<'a',  
  60.       capflag=1;
  61.       ty=ty+('a'-'A')*ones(1,size(ty)*[0;1]);
  62.    else
  63.       capflag=0;
  64.    end
  65.  
  66.    % Pad ty with spaces to length 4
  67.    ty=[ty '    '];
  68.    ty=ty(1:4);
  69.  
  70.    % Assemble the string V containing variable names without SUF
  71.    if ty=='gsm ',                  % General statespace
  72.        v='sm,dimx,dimu,dimy';       
  73.    elseif ty=='gdes',              % General descriptor
  74.        v='e,sm,dimx,dimu,dimy';
  75.    elseif ty=='gpsm';              % General polynom. sys. matrix
  76.        v='psm,deg,dimx,dimu,dimy';
  77.    elseif ty=='ss  '               % Standard Statespace
  78.        v='a,b,c,d';
  79.    elseif ty=='des ';              % Descriptor System
  80.        v='a,b,c,d,e';
  81.    elseif ty=='tss '               % Two-port Statespace 
  82.        v='a,b1,b2,c1,c2,d11,d12,d21,d22';
  83.    elseif ty=='tdes'               % Two-port Descriptor
  84.        v='a,b1,b2,c1,c2,d11,d12,d21,d22,e';
  85.    elseif ty=='tf  '
  86.        v='num,den';
  87.    elseif ty=='tfm '
  88.        v='num,den,n,m';
  89.    elseif ty=='sm  '
  90.        v='sm,dim';
  91.    elseif ty=='tsm '
  92.        v='tsm,dim';
  93.    elseif ty=='imp '
  94.        v='y,ts,nu,ny';
  95.    else
  96.        v=['Error, invalid system type designator ''' ty1 ''''];
  97.        n=0;
  98.        return
  99.    end
  100.       
  101.    % Capitalize V if needed
  102.    if capflag==1,
  103.       ind=find(v>='a');
  104.       v(ind)=v(ind)+('A'-'a')*ones(1,size(ind)*[0;1]);
  105.    end
  106.  
  107.    % Now insert suffix just after alphabetic part of each variable name
  108.    v = [',' v ','];
  109.    ind = find(v==',');
  110.    [rind,cind]=size(ind);
  111.    vtemp='';
  112.    for j=1:cind-1,
  113.       vj=v(ind(j)+1:ind(j+1)-1);
  114.       nj=find(vj<'A');
  115.       if max(size(nj))>0,
  116.          [rvj,cvj]=size(vj);
  117.          vj1=vj(1:nj(1)-1);
  118.          vj2=vj(nj(1):cvj);
  119.       else
  120.          vj1 =vj;
  121.          vj2 ='';
  122.       end
  123.       vtemp= [vtemp ',' vj1 suf vj2];
  124.    end
  125.    n=max(size(find(vtemp==',')));
  126.    vtemp(1)='';  % Remove leading comma
  127.    v=vtemp;
  128. % ------- End of VRSYS.M -----------RYC/MGS 10/25/90 %