home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / hinfnorm.m < prev    next >
Text File  |  1999-03-05  |  5KB  |  136 lines

  1. # Copyright (C) 1996,1998 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function [g, gmin, gmax] = hinfnorm(sys,tol,gmin,gmax,ptol)
  18.   # Usage: [g gmin gmax] = hinfnorm(sys[,tol,gmin,gmax,ptol])
  19.   #
  20.   # Computes the H infinity norm of a system data structure
  21.   # sys = system data structure
  22.   # tol = H infinity norm search tolerance (default: 0.001)
  23.   # gmin = minimum value for norm search (default: 1e-9)
  24.   # gmax = maximum value for norm search (default: 1e+9)
  25.   # ptol: pole tolerance:
  26.   #       if sys is continuous, poles with 
  27.   #         |real(pole)| < ptol*||H|| (H is appropriate Hamiltonian)
  28.   #         are considered to be on the imaginary axis.  
  29.   #       if sys is discrete, poles with
  30.   #         |abs(pole)-1| < ptol*||[s1,s2]|| (appropriate symplectic pencil)
  31.   #         are considered to be on the unit circle
  32.   #       Default: 1e-9
  33.   #
  34.   # References:
  35.   # Doyle, Glover, Khargonekar, Francis, "State space solutions to standard
  36.   #    H2 and Hinf control problems", IEEE TAC August 1989
  37.   # Iglesias and Glover, "State-Space approach to discrete-time Hinf control,"
  38.   #    Int. J. Control, vol 54, #5, 1991
  39.   # Zhou, Doyle, Glover, "Robust and Optimal Control," Prentice-Hall, 1996
  40.  
  41.   if((nargin == 0) || (nargin > 4))
  42.     usage("[g gmin gmax] = hinfnorm(sys[,tol,gmin,gmax,ptol])");
  43.   elseif(!is_struct(sys))
  44.     error("Sys must be a system data structure");
  45.   endif
  46.  
  47.   # set defaults where applicable
  48.   if(nargin < 5)
  49.     ptol = 1e-9;    # pole tolerance
  50.   endif
  51.   if(nargin < 4)
  52.     gmax = 1e9;        # max gain value
  53.   endif
  54.  
  55.   dflg = is_digital(sys);
  56.   sys = sysupdate(sys,"ss");
  57.   [A,B,C,D] = sys2ss(sys);
  58.   [n,nz,m,p] = sysdimensions(sys);
  59.  
  60.   # eigenvalues of A must all be stable
  61.   if(!is_stable(sys))
  62.     warning(["hinfnorm: unstable system (is_stable, ptol=",num2str(ptol), ...
  63.       "), returning Inf"]);
  64.     g = Inf;
  65.   endif
  66.  
  67.   Dnrm = norm(D);
  68.   if(nargin < 3)
  69.     gmin = max(1e-9,Dnrm);     # min gain value
  70.   elseif(gmin < Dnrm)
  71.     warning(["hinfnorm: setting Gmin=||D||=",num2str(Dnrm)]);
  72.   endif
  73.  
  74.   if(nargin < 2)
  75.     tol = 0.001;    # convergence measure for gmin, gmax
  76.   endif
  77.  
  78.   # check for scalar input arguments 2...5
  79.   if( ! (is_scalar(tol) && is_scalar(gmin) 
  80.     && is_scalar(gmax) && is_scalar(ptol)) )
  81.     error("hinfnorm: tol, gmin, gmax, ptol must be scalars");
  82.   endif
  83.  
  84.   In = eye(n+nz);
  85.   Im = eye(m);
  86.   Ip = eye(p);
  87.   # find the Hinf norm via binary search
  88.   while((gmax/gmin - 1) > tol)
  89.     g = (gmax+gmin)/2;
  90.  
  91.     if(dflg)
  92.       # multiply g's through in formulas to avoid extreme magnitudes...
  93.       Rg = g^2*Im - D'*D;
  94.       Ak = A + (B/Rg)*D'*C;
  95.       Ck = g^2*C'*((g^2*Ip-D*D')\C);
  96.  
  97.       # set up symplectic generalized eigenvalue problem per Iglesias & Glover
  98.       s1 = [Ak , zeros(nz) ; -Ck, In ];
  99.       s2 = [In, -(B/Rg)*B' ; zeros(nz) , Ak' ];
  100.  
  101.       # guard against roundoff again: zero out extremely small values
  102.       # prior to balancing
  103.       s1 = s1 .* (abs(s1) > ptol*norm(s1,"inf"));
  104.       s2 = s2 .* (abs(s2) > ptol*norm(s2,"inf"));
  105.       [cc,dd,s1,s2] = balance(s1,s2);
  106.       [qza,qzb,zz,pls] = qz(s1,s2,"S");    # ordered qz decomposition
  107.       eigerr = abs(abs(pls)-1);
  108.       normH = norm([s1,s2]);
  109.       Hb = [s1, s2];
  110.  
  111.       # check R - B' X B condition (Iglesias and Glover's paper)
  112.       X = zz((nz+1):(2*nz),1:nz)/zz(1:nz,1:nz);
  113.       dcondfailed = min(real( eig(Rg - B'*X*B)) < ptol);
  114.     else
  115.       Rinv = inv(g*g*Im - (D' * D));
  116.       H = [A + B*Rinv*D'*C,        B*Rinv*B'; ...
  117.            -C'*(Ip + D*Rinv*D')*C, -(A + B*Rinv*D'*C)'];
  118.       # guard against roundoff: zero out extremely small values prior 
  119.       # to balancing
  120.       H = H .* (abs(H) > ptol*norm(H,"inf"));
  121.       [DD,Hb] = balance(H);
  122.       pls = eig(Hb);
  123.       eigerr = abs(real(pls));
  124.       normH = norm(H);
  125.       dcondfailed = 0;        # digital condition; doesn't apply here
  126.     endif
  127.     if( (min(eigerr) <= ptol * normH) | dcondfailed)
  128.       gmin = g;
  129.     else
  130.       gmax = g;
  131.     endif
  132.   endwhile
  133. endfunction
  134.