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

  1. function [acp,bcp,ccp,dcp,mu,logd0,ad,bd,cd,dd,gam] = musyn(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14,Z15,Z16)
  2. % [SS_CP,MU,LOGD,SS_D,GAM] = MUSYN(TSS_,W) or
  3. % [SS_CP,MU,LOGD,SS_D,GAM] = MUSYN(TSS_,W,GAMIND,AUX,LOGD0,N,BLKSZ,FLAG)
  4. % automates the MU-synthesis D-F iteration using hinfopt, fitd and ssv.
  5. % Inputs: TSS_ = mksys(A,B1,B2,...,D21,D22)  --- the plant
  6. %         W    = frequency vector used for curve fitting by fitd
  7. % Outputs:
  8. %         SS_CP = mksys(ACP,BCP,CCP,DCP) --- MU-synthesis controller
  9. %         LOGD     --- log magnitude of closed-loop
  10. %  diagonal scaling from psv.m
  11.  
  12.  
  13. %  R. Y. Chiang & M. G. Safonov (1992)
  14. % Copyright (c) 1992 by the MathWorks, Inc.
  15. % All Rights Reserved.
  16.  
  17.  
  18.  
  19.  
  20. nag1 = nargin;
  21. nag2 = nargout;
  22.  
  23. % Expand system input arguments and modify NARGIN as needed:
  24. inargs = '(A,B1,B2,C1,C2,D11,D12,D21,D22,w,gamind,aux,logd0,n,blksz,flag)';
  25. eval(mkargs(inargs,nargin,'tss'))
  26.  
  27. % Now define defaults for input variables:
  28. if nargin<10, 
  29.   error('Too few input arguments')
  30. end
  31.  
  32. % Set any absent optional input variables to []:
  33. if nargin<11, gamind=[]; end
  34. if nargin<12,    aux=[]; end
  35. if nargin<13,  logd0=[]; end
  36. if nargin<14,      n=[]; end
  37. if nargin<15,  blksz=[]; end
  38. if nargin<16,   flag=[]; end
  39.  
  40. % Determine the number of uncertainty blocks NBLKS from BLKSZ using
  41. % same rules as in psv.m and fitd.m
  42. temp=max(size(blksz));
  43. if temp>1        % If BLKSZ is a vector
  44.    nblks=temp;            % NBLKS = size of BLKSZ vector
  45. else             % otherwise
  46.    [rD11,cD11]=size(D11);
  47.    nblks=rD11;            % default NBLKS=max(size(D11)) and
  48.    if rD11~=cD11,         % D11 must be a square matrix in this case
  49.        error('plant D11 matrix must be square')
  50.    end
  51.    if temp==1,
  52.                           % default NBLKS=max(size(D11))/BLKSZ
  53.       nblks=nblks/blksz(1);
  54.       if nblks*blksz(1)~=rD11,
  55.          error('size(D11) should be a multiple BLKSZ')
  56.       end
  57.    end
  58. end
  59.  
  60. % Do some cursory dimensional compatibility checks on w, logd0, blksz
  61. nblklogd0 = min(size(logd0));
  62. nwlogd0 = max(size(logd0));
  63. if min([nblks,nblklogd0])>1,
  64.    if nblks~=nblklogd0,
  65.      error('Number of rows of LOGD0 must equal dimension of vector BLKSZ'),
  66.    end
  67. end
  68. nw=max(size(w));
  69. if nwlogd0>0 & nwlogd0~=nw,
  70.    error('Number of columns of LOGD0 must equal number of frequences W'),
  71. end
  72.  
  73. % Set flag if mu plot is to be computed
  74. muflag=0;
  75. if (xsflag & nargout>1) | nargout>4
  76.    muflag=1;
  77. end
  78.  
  79. % Initialize variables for D-F iteration loop
  80. if min(size(aux))>0
  81.    tol=aux(1)  %  Tolerance for terminating D-F iteration loop
  82. else
  83.    tol=0.01;
  84. end
  85. gams=Inf;
  86. done=0;    % 0:=FALSE; D-F iteration loop terminates when DONE=1 (TRUE).
  87.  
  88. % Commence D-F iteration loop:
  89. while ~done,   
  90.  % Augment plant with a state-space curve-fit to the bode data LOGD0:
  91.                                 % If LOGD is constant times identity
  92.  if min(size(logd0))==0, 
  93.      noscale=1;
  94.  elseif min(abs(logd0(:)))==max(abs(logd0(:)))
  95.      noscale=1;     
  96.  else
  97.      noscale=0;
  98.  end
  99.  if noscale,
  100.    logd0=zeros(nblks,nw);           % set LOGD0 to zero
  101.    logdfit=logd0;                  % set LOGDFIT to zero
  102.    AD =A;   BD1 =B1;   BD2 =B2;    % and use unaugmented plant
  103.    CD1=C1;  DD11=D11;  DD12=D12;
  104.    CD2=C2;  DD21=D21;  DD22=D22;
  105.  else                           % otherwise,
  106.                                    % curve-fit logd0 using fitd.m
  107.    [ad,bd,cd,dd,logdfit]=fitd(logd0,w,n,blksz);
  108.                                    % and use augd.m to augment the 
  109.                                    % plant with the fitted diagonal-
  110.                                    % scaling [ad,bd,cd,dd].
  111.    [AD,BD1,BD2,CD1,CD2,DD11,DD12,DD21,DD22]=...
  112.        augd(A,B1,B2,C1,C2,D11,D12,D21,D22,ad,bd,cd,dd);
  113.  end
  114.  
  115.  % Do hinfopt.m on the diagonally-scaled, augmented plant:
  116.  [gam,acp,bcp,ccp,dcp,acl,bcl,ccl,dcl]=...
  117.      hinfopt(AD,BD1,BD2,CD1,CD2,DD11,DD12,DD21,DD22,gamind,aux);
  118.  
  119.  % Test for convergence:
  120.  if gams-gam > tol,  % If cost decrease is greater than TOL
  121.     acls=acl;  bcls=bcl;       % then store current values
  122.     ccls=ccl;  dcls=dcl;       % and continue D-F loop
  123.     acps=acp;  bcps=bcp;
  124.     ccps=ccp;  dcps=dcp;
  125.     mus=mu;
  126.     logd0s=logd0;
  127.     gams=gam;
  128.  else                      % otherwise
  129.     if gams-gam < 0;              % first, check if cost increased
  130.       acl=acls;  bcl=bcls;            % if so, restore the values
  131.       ccl=ccls;  dcl=dcls;            % from the previous iteration
  132.       acp=acps;  bcp=bcps;
  133.       ccp=ccps;  dcp=dcps;
  134.       mu=mus;
  135.       logd0=logd0s;
  136.       gam=gams;
  137.     end
  138.     done=1;                       % prepare to exit D-F iteration loop
  139.  end                 % End of convergence test          
  140.  
  141.  % Do ssv.m to evaluate MU bode and update LOGD0, if needed:
  142.  if ~done | muflag,
  143.     [mu,logd1]=ssv(acl,bcl,ccl,dcl,w,blksz,'psv');
  144.     if noscale,
  145.          logd0=logd1;
  146.     else
  147.          logd0=logd1+logdfit;         
  148.     end
  149.  end
  150. end   % End D-F iteration loop
  151.  
  152. % If input was in SYSTEM form, then convert output to SYSTEM form:
  153. if xsflag,
  154.    if nag2>6, 
  155.       disp('WARNING:  Too many output arguments for SYSTEM form output'),
  156.    end
  157.    acp=mksys(acp,bcp,ccp,dcp);
  158.    bcp=mu;
  159.    ccp=logd0;
  160.    dcp=mksys(ad,bd,cd,dd);
  161.    mu=gam;
  162. end
  163.  
  164. % ------------ End of MUSYN.M -----------------%  RYC/MGS 5/19/92 %
  165.