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

  1. % function [k,g,gfin,ax,ay,hamx,hamy] = 
  2. %                 hinfsyn(p,nmeas,ncon,gmin,gmax,tol,ricmethd,epr,epp) 
  3. %
  4. %  This function computes the H-infinity (sub) optimal n-state
  5. %  controller, using Glover's and Doyle's 1988 result, for a system P.
  6. %  the system P is partitioned:   
  7. %                          | a   b1   b2   | 
  8. %              p    =      | c1  d11  d12  |
  9. %                          | c2  d21  d22  | 
  10. %   where b2 has column size of the number of control inputs (NCON)
  11. %   and c2 has row size of the number of measurements (NMEAS) being
  12. %   provided to the controller.
  13. %   inputs:
  14. %      P        -   interconnection matrix for control design
  15. %      NMEAS    -   # controller inputs (np2)
  16. %      NCON     -   # controller outputs (nm2)
  17. %      GMIN     -   lower bound on gamma
  18. %      GMAX     -   upper bound on gamma
  19. %      TOL      -   relative difference between final gamma values
  20. %      RICMETHD -   Riccati solution via
  21. %                     1 - eigenvalue reduction
  22. %                     2 - real schur decomposition  (default)
  23. %      EPR      -   measure of when real(eig) of Hamiltonian is zero
  24. %                    (default EPR = 1e-10)
  25. %      EPP      -  positive definite determination of xinf solution
  26. %                    (default EPP = 1e-6)
  27. %    outputs:
  28. %      K       -   H-infinity controller
  29. %      G       -   closed-loop system
  30. %      GFIN    -   final gamma value used in control design
  31. %      AX      -   X-Riccati solution as a VARYING matrix with 
  32. %                     independent variable gamma (optional)
  33. %      AY      -   Y-Riccati solution as a VARYING matrix with 
  34. %                      independent variable gamma (optional)
  35. %      HAMX    -   X-Hamiltonian matrix as a VARYING matrix with 
  36. %                      independent variable gamma (optional)
  37. %      HAMY    -   Y-Hamiltonian matrix as a VARYING matrix with 
  38. %                      independent variable gamma (optional)
  39. %
  40. %   See also: H2SYN, H2NORM, HINFFI, HINFNORM, RIC_EIG, and RIC_SCHR
  41.  
  42. function [k,g,gfin,ax,ay,hamx,hamy] = ...
  43.           hinfsyn(p,nmeas,ncon,gmin,gmax,tol,imethd,epr,epp) 
  44. %
  45. %   the following assumptions are made:
  46. %    (i)   (a,b2,c2) is stabilizable and detectable
  47. %    (ii)  d12 and d21 have full rank
  48. %     on return, the eigenvalues in egs must all be > 0
  49. %     for the closed-loop system to be stable and to
  50. %     have inf-norm less than GAM.
  51. %     this program provides a gamma iteration using a
  52. %     bisection method, it iterates on the value
  53. %     of GAM to approach the H-inf optimal controller.
  54. %                                    np  nm1  nm2
  55. %   The system p is partitioned:   | a   b1   b2   | np
  56. %                                  | c1  d11  d12  | np1
  57. %                                  | c2  d21  d22  | np2
  58. % Reference Paper:
  59. %       'State-space formulae for all stabilizing controllers
  60. %         that satisfy and h-infinity-norm bound and relations
  61. %         to risk sensitivity,' by keith glover and john doyle,
  62. %         systems & control letters 11, oct, 1988, pp 167-172.
  63.  
  64. storxinf = [];
  65. storyinf = [];
  66. storhx = [];
  67. storhy = [];
  68. gammavecxi = [];
  69. gammavecyi = [];
  70. gammavechx = [];
  71. gammavechy = [];
  72.  
  73. if nargin == 0
  74.  disp('usage: [k,g,gfin] = hinfsyn(p,nmeas,ncon,gmin,gmax,tol,ricmethd,epr,epp) ')
  75.  return
  76. end
  77. if nargin <= 5
  78.  disp('usage: [k,g,gfin] = hinfsyn(p,nmeas,ncon,gmin,gmax,tol,ricmethd,epr,epp) ')
  79.  error('incorrect number of input arguments')
  80.  return
  81. end
  82. % setup default cases
  83. if nargin == 6
  84.   imethd = 2;
  85.   epr = 1e-10;
  86.   epp = 1e-6;
  87. elseif nargin == 7
  88.   epr = 1e-10;
  89.   epp = 1e-6;
  90. elseif nargin == 8
  91.   epp = 1e-6;
  92. end
  93.   
  94. gam2=gmax;
  95. gam0=gmax;
  96. if gmin > gmax
  97.   error(' gamma min is greater than gamma max')
  98.   return
  99. end
  100. % save the input system to form the closed-loop system 
  101. pnom = p;
  102. niter = 1;
  103. npass = 0;
  104. first_it = 1;
  105. totaliter = 0;
  106. % fprintf('checking rank conditions: ');
  107.   [p,r12,r21,fail] = hinf_st(p,nmeas,ncon);
  108.   if fail == 1,
  109.     fprintf('\n')
  110.     return
  111.   end
  112.  
  113. %            gamma iteration
  114.  
  115. fprintf('Test bounds:  %10.4f <  gamma  <=  %10.4f\n\n',gmin,gmax)
  116. fprintf('  gamma    hamx_eig  xinf_eig  hamy_eig   yinf_eig   nrho_xy   p/f\n')
  117.  
  118.  while niter==1
  119.   totaliter = totaliter + 1;
  120.   if first_it ==1        % first iteration checks gamma max
  121.     gam = gmax;
  122.   else
  123.     gam=((gam2+gam0)/2.);
  124.     gamall=[gam0 gam gam2];
  125.   end
  126.   if gam < 1000
  127.     fprintf('%9.3f  ',gam)
  128.   else
  129.     fprintf('%9.3e  ',gam)
  130.   end
  131.   [xinf,yinf,f,h,fail,hmx,hmy,hxmin,hymin] = ... 
  132.                         hinf_gam(p,nmeas,ncon,epr,gam,imethd);
  133.   if nargout >= 4
  134.     if isempty(xinf)
  135.       % don't update the matrix
  136.     else
  137.       gammavecxi = [gammavecxi ; gam];
  138.       storxinf = [storxinf ; xinf];
  139.     end
  140.     if nargout >= 5
  141.       if isempty(yinf)
  142.         % don't update the matrix
  143.       else
  144.         gammavecyi = [gammavecyi ; gam];
  145.         storyinf = [storyinf ; yinf];
  146.       end
  147.       if nargout >= 6
  148.         if isempty(hmx)
  149.           % don't update the matrix
  150.         else
  151.           gammavechx = [gammavechx ; gam];
  152.           storhx = [storhx ; hmx];
  153.         end
  154.         if nargout >= 7
  155.           if isempty(hmy)
  156.             % don't update the matrix
  157.           else
  158.            gammavechy = [gammavechy ; gam];
  159.            storhy = [storhy ; hmy];
  160.           end
  161.         end
  162.       end
  163.     end
  164.   end
  165. %
  166. % check the conditions for a solution to the h-infinity control problem
  167. %
  168.   if fail == 0
  169.     xe = eig(xinf);
  170.     ye = eig(yinf);
  171.     xye = eig(xinf*yinf);
  172.     xeig = min(real(xe));
  173.     yeig = min(real(ye));
  174.     xyinfe = max(abs(xye));
  175.     index = find(real(xe)==xeig);
  176.     mprintf(hxmin,'%8.1e',' ');
  177.     mprintf(real(xe(index(1))),' %8.1e',' ');
  178.     index = find(real(ye)==yeig);
  179.     mprintf(hymin,' %8.1e ',' ');
  180.     mprintf(real(ye(index(1))),' %8.1e',' ');
  181.  
  182. % scaled rho(xy)
  183.     fprintf('  %7.4f   ',xyinfe/gam/gam)
  184.     if xeig < -epp | yeig < -epp | xeig == nan | yeig == nan;
  185.       npass=1;
  186.     end
  187.     if xyinfe/gam/gam > 1
  188.       npass=1;
  189.     end
  190.   else
  191.     if isempty(xinf)
  192.       mprintf(hxmin,'%8.1e',' ');
  193.       fprintf('  ******* ')
  194.       if isempty(yinf)
  195.         mprintf(hymin,' %8.1e ',' ');
  196.         fprintf('  ******* ')
  197.         fprintf('   ******   ')
  198.       else
  199.         ye = eig(yinf);
  200.         mprintf(hymin,' %8.1e ',' ');
  201.         mprintf(min(real(ye)),' %8.1e',' ');
  202.         fprintf('   ******   ')
  203.       end
  204.     else
  205.       xe = eig(xinf);
  206.       mprintf(hxmin,'%8.1e',' ');
  207.       mprintf(min(real(xe)),' %8.1e ',' ');
  208.       mprintf(hymin,' %8.1e ',' ');
  209.       fprintf(' ******* ')
  210.       fprintf('   ******   ')
  211.     end
  212.     npass = 1;
  213.   end
  214.  
  215.   if npass == 1
  216.     fprintf(' f \n')
  217.   else
  218.     fprintf(' p \n')
  219.   end
  220. %
  221. % check the gamma iteration
  222. %
  223.  if first_it == 1;
  224.    if npass == 0;
  225.      gam0 = gmin; 
  226.      gam2 = gmax; 
  227.      xinffin = xinf; 
  228.      yinffin = yinf;
  229.      fsave = f;
  230.      hsave = h; 
  231.      gfin = gmax;
  232.      first_it = 0;
  233.      if gmin == gmax
  234.        niter = 0;           % stop since gmax = gmin
  235.      end
  236.   else
  237.      niter = 0;
  238.      fprintf('Gamma max, %10.4f, is too small !!\n',gmax);
  239. % save output data
  240.      if nargout >= 4
  241.        ax = vpck(storxinf,gammavecxi);
  242.        if nargout >= 5
  243.          ay = vpck(storyinf,gammavecyi);
  244.          if nargout >= 6
  245.            hamx = vpck(storhx,gammavechx);
  246.            if nargout >= 7
  247.              hamy = vpck(storhy,gammavechy);
  248.         end
  249.          end
  250.        end
  251.      end
  252.      return
  253.    end    
  254.  else
  255.    if abs(gam - gam0) < tol
  256.      niter = 0;
  257.      if npass == 0
  258.        gfin = gam;
  259.        xinffin = xinf;
  260.        yinffin = yinf;
  261.      fsave = f;
  262.      hsave = h; 
  263.      else
  264.        gfin = gam2; 
  265.      end
  266.    else
  267.      if npass == 0;
  268.        gam2 = gam;
  269.        xinffin = xinf;
  270.        yinffin = yinf;
  271.      fsave = f;
  272.      hsave = h; 
  273.      else
  274.        gam0 = gam;
  275.      end
  276.    end
  277.    npass = 0;
  278.  end
  279. end
  280. xinf = xinffin; 
  281. yinf = yinffin; 
  282. %  finished with gamma iteration
  283. fprintf('\n Gamma value achieved: %10.4f\n',gfin)
  284.  
  285. [k] = hinf_c(p,nmeas,ncon,xinf,yinf,fsave,hsave,gfin,r12,r21);
  286. [g] = starp(pnom,k,nmeas,ncon);
  287.  
  288. % save output data
  289.   if nargout >= 4
  290.     ax = vpck(storxinf,gammavecxi);
  291.     if nargout >= 5
  292.       ay = vpck(storyinf,gammavecyi);
  293.       if nargout >= 6
  294.         hamx = vpck(storhx,gammavechx);
  295.         if nargout >= 7
  296.           hamy = vpck(storhy,gammavechy);
  297.         end
  298.       end
  299.     end
  300.   end
  301. %
  302. % Copyright MUSYN INC 1991,  All Rights Reserved
  303.