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

  1. function [gam_opt,acp,bcp,ccp,dcp,acl,bcl,ccl,dcl] = hinfopt(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11)
  2. % [GAM_OPT,SS_CP,SS_CL] = HINFOPT(TSS_,GAMIND,AUX) or
  3. % [GAM_OPT,ACP,BCP,CCP,DCP,ACL,BCL,CCL,DCL] = HINFOPT(A,B1,..,GAMIND,AUX)
  4. %  does H-inf Gamma-Iteration to compute optimal H-Infinity control 
  5. %  laws for a given system Tcl:(TSS_) via the improved Loop-Shifting 
  6. %  two-Riccati formulae. "Gam_opt" is the optimal "gamma" for which
  7. %
  8. %                   || gamma * Tcl(gamind,:)   ||
  9. %                   ||                         ||     <= 1 
  10. %                   ||         Tcl(otherind,:) || inf
  11. %  where
  12. %       Tcl(gamind,:) contains the rows to be weighted by "gamma",
  13. %       Tcl(otherind,:) contains the other rows of Tcl.
  14. %  Inputs:  Tcl: TSS_ = mksys(A,B1,B2,C1,C2,D11,D12,D21,D22);
  15. %       Optional Inputs:
  16. %           gamind: the index of the outputs to be scaled by gamma
  17. %                   (default: all output channels)
  18. %           aux   : [tol, maxgam, mingam] (default: [0.01 1 0])
  19. %                   tol   : tolerance for stopping the iteration
  20. %                   maxgam: initial guess for maximum "gam_opt"
  21. %                   mingam: initial guess for minimum "gam_opt"
  22. %  Outputs: gam_opt (optimal gamma)
  23. %        H-Inf optimal controller:   ss_cp = mksys(acp,bcp,ccp,dcp)
  24. %        gamma-weighted closed-loop: ss_cl = mksys(acl,bcl,ccl,dcl)
  25.  
  26. %  R. Y. Chiang & M. G. Safonov (1/1989)
  27. % Copyright (c) 1989 by the MathWorks, Inc.
  28. % All Rights Reserved.
  29.  
  30. nag1 = nargin;
  31. nag2 = nargout;
  32.  
  33. if nag1 == 1 | nag1 == 9
  34.    % case (TSS_)
  35.    inargs = '(A,B1,B2,C1,C2,D11,D12,D21,D22)';  
  36.    eval(mkargs(inargs,nargin,'tss'))
  37.    gamind = 1:size(C1)*[1;0]; 
  38.    aux = [0.01 1 0];
  39. end
  40. if nag1 == 2 | nag1 == 10
  41.    % case (TSS_,gamind)
  42.    inargs = '(A,B1,B2,C1,C2,D11,D12,D21,D22,gamind)'; 
  43.    eval(mkargs(inargs,nargin,'tss'))
  44.    aux = [0.01 1 0];
  45. end
  46. if nag1 == 3 | nag1 == 11
  47.    % case(TSS_,gamind,aux)
  48.    inargs = '(A,B1,B2,C1,C2,D11,D12,D21,D22,gamind,aux)';
  49.    eval(mkargs(inargs,nargin,'tss'))
  50. end
  51.  
  52. if max(size(gamind))==0, gamind = 1:size(C1)*[1;0]; end
  53. if max(size(aux))==0, aux = [0.01 1 0]; end
  54.  
  55. %
  56. if size(aux)*[0;1] == 1
  57.    tol = aux(1); rho_h = 1; rho_l = 0;
  58. end
  59. if size(aux)*[0;1] == 2
  60.    tol = aux(1); rho_h = aux(2); rho_l = 0;
  61. end
  62. if size(aux)*[0;1] == 3
  63.    tol = aux(1); rho_h = max(aux(2:3)); rho_l = min(aux(2:3));
  64. end
  65. %
  66. rho_h = max([rho_h 1.e-7]); rho_l = max([rho_l 0]);
  67. mingam = rho_l; maxgam = rho_h;
  68. %
  69. % ----- Initialize all variables:
  70. %
  71. iteration = 0; 
  72. rhoi = max([0, maxgam]);         % initial guesss for gamma
  73. p_opt = 0; p = 0;                % initialize gamma iteration counters
  74. relerr = 1.e6;                   % initialize to ensure at least one iteration
  75. xflag = 0;                       % initially not yet sure if maxgam is valid
  76. yflag = 0;                       % initially not yet sure if mingam is valid
  77. if rho_l == 0
  78.    yflag = 1;
  79. end
  80. %
  81. c1 = C1; d11 = D11; d12 = D12;
  82. gam_opt = 0;
  83. %
  84. while relerr > tol
  85.     p = p+1; iteration(p) = p;
  86.     if p == 1
  87.        clc
  88.        disp(' ')
  89.        disp('                   << H-Infinity Optimal Control Synthesis >>')
  90.        disp(' ')
  91.        disp('  No     Gamma    D11<=1   P-Exist   P>=0   S-Exist   S>=0   lam(PS)<1    C.L.')
  92.        disp(' ------------------------------------------------------------------------------')
  93.     end
  94.     C1(gamind,:)  = rhoi*c1(gamind,:);
  95.     D11(gamind,:) = rhoi*d11(gamind,:);
  96.     D12(gamind,:) = rhoi*d12(gamind,:);
  97.     [tacp,tbcp,tccp,tdcp,tacl,tbcl,tccl,tdcl,hinfo] = hinf(...
  98.                              A,B1,B2,C1,C2,D11,D12,D21,D22,0);
  99.     hexist  = setstr(hinfo(1:4));
  100.     D11flag = setstr(hinfo(5:8));
  101.     Pexist  = setstr(hinfo(9:12));
  102.     Pflag   = setstr(hinfo(13:16));
  103.     Sexist  = setstr(hinfo(17:20));
  104.     Sflag   = setstr(hinfo(21:24));
  105.     PSflag  = setstr(hinfo(25:28));
  106.     RHP_cl = hinfo(29);
  107.     if RHP_cl > 0
  108.        CLflag = 'UNST';
  109.     else
  110.        CLflag = 'STAB';
  111.     end
  112.     lamps_max = hinfo(30);
  113.     if hexist == 'FAIL'
  114.        gamaflg = 1;
  115.     else
  116.        gamaflg = 0;
  117.     end
  118.     if gamaflg + RHP_cl == 0
  119.        rho_l = rhoi; yflag = 1;
  120.        acp = tacp; bcp = tbcp; ccp = tccp; dcp = tdcp;
  121.        acl = tacl; bcl = tbcl; ccl = tccl; dcl = tdcl;
  122.        gam_opt = rhoi; p_opt = p;
  123.     else
  124.        rho_h = rhoi; 
  125.        xflag = 1;
  126.     end
  127.     disp([sprintf('%4.0f',p),sprintf('%12.4e',rhoi),'   ', D11flag,'     ',Pexist,'     ',Pflag,'    ',Sexist,'     ',Sflag,'      ',PSflag,'      ',CLflag])
  128.     if xflag == 0
  129.        rhoi = 2*rhoi;
  130.     else
  131.        if yflag == 0
  132.           if rhoi == rho_l
  133.              rho_l = rho_l/2;
  134.              rhoi = rho_l;
  135.           else
  136.              rhoi = rho_l;
  137.           end
  138.        end
  139.        rhoi = (rho_l + rho_h)/2;
  140.     end
  141.     if rho_l == 0
  142.        relerr = 1.e6;
  143.     else
  144.        relerr = abs((rho_h - rho_l)/rho_l);
  145.     end
  146.     if xflag*yflag < 0.5, relerr = 1.e6; end;
  147. end
  148. %
  149. disp(' ')
  150. disp(['      Iteration no. ', int2str(p_opt),...
  151. ' is your best answer under the tolerance: ', sprintf('%8.4f',tol), ' .'])
  152. %
  153. if xsflag
  154.    acp = mksys(acp,bcp,ccp,dcp);
  155.    if nag2 > 2
  156.       bcp = mksys(acl,bcl,ccl,dcl);
  157.    end
  158. end
  159. %
  160. % ------- End of HINFOPT.M ---- RYC/MGS %