diff scripts/control/hinf/hinfnorm.m @ 7131:a184bc985c37

[project @ 2007-11-08 15:55:02 by jwe]
author jwe
date Thu, 08 Nov 2007 15:55:02 +0000
parents a1dbe9d80eee
children 38fe664f0ef1
line wrap: on
line diff
--- a/scripts/control/hinf/hinfnorm.m	Thu Nov 08 15:28:41 2007 +0000
+++ b/scripts/control/hinf/hinfnorm.m	Thu Nov 08 15:55:02 2007 +0000
@@ -115,93 +115,93 @@
 
 function [g, gmin, gmax] = hinfnorm (sys, tol, gmin, gmax, ptol)
 
-  if((nargin == 0) || (nargin > 4))
+  if (nargin == 0 || nargin > 4)
     print_usage ();
-  elseif(!isstruct(sys))
-    error("Sys must be a system data structure");
+  elseif (! isstruct (sys))
+    error ("Sys must be a system data structure");
   endif
 
   ## set defaults where applicable
-  if(nargin < 5)
+  if (nargin < 5)
     ptol = 1e-9;        # pole tolerance
   endif
-  if(nargin < 4)
+  if (nargin < 4)
     gmax = 1e9;         # max gain value
   endif
 
-  dflg = is_digital(sys);
-  sys = sysupdate(sys,"ss");
-  [A,B,C,D] = sys2ss(sys);
-  [n,nz,m,p] = sysdimensions(sys);
+  dflg = is_digital (sys);
+  sys = sysupdate (sys, "ss");
+  [A, B, C, D] = sys2ss (sys);
+  [n, nz, m, p] = sysdimensions (sys);
 
   ## eigenvalues of A must all be stable
-  if(!is_stable(sys))
-    warning(["hinfnorm: unstable system (is_stable, ptol=",num2str(ptol), ...
-      "), returning Inf"]);
+  if (! is_stable (sys))
+    warning ("hinfnorm: unstable system (is_stable, ptol=%g), returning Inf",
+	     ptol);
     g = Inf;
   endif
 
-  Dnrm = norm(D);
-  if(nargin < 3)
-    gmin = max(1e-9,Dnrm);      # min gain value
-  elseif(gmin < Dnrm)
-    warning(["hinfnorm: setting Gmin=||D||=",num2str(Dnrm)]);
+  Dnrm = norm (D);
+  if (nargin < 3)
+    gmin = max (1e-9, Dnrm);      # min gain value
+  elseif (gmin < Dnrm)
+    warning ("hinfnorm: setting Gmin=||D||=%g", Dnrm);
   endif
 
-  if(nargin < 2)
+  if (nargin < 2)
     tol = 0.001;        # convergence measure for gmin, gmax
   endif
 
   ## check for scalar input arguments 2...5
-  if( ! (isscalar(tol) && isscalar(gmin)
-        && isscalar(gmax) && isscalar(ptol)) )
-    error("hinfnorm: tol, gmin, gmax, ptol must be scalars");
+  if (! isscalar (tol) && isscalar (gmin)
+      && isscalar (gmax) && isscalar (ptol)) )
+    error ("hinfnorm: tol, gmin, gmax, ptol must be scalars");
   endif
 
-  In = eye(n+nz);
-  Im = eye(m);
-  Ip = eye(p);
+  In = eye (n+nz);
+  Im = eye (m);
+  Ip = eye (p);
   ## find the Hinf norm via binary search
-  while((gmax/gmin - 1) > tol)
+  while (gmax/gmin - 1 > tol)
     g = (gmax+gmin)/2;
 
-    if(dflg)
+    if (dflg)
       ## multiply g's through in formulas to avoid extreme magnitudes...
       Rg = g^2*Im - D'*D;
       Ak = A + (B/Rg)*D'*C;
       Ck = g^2*C'*((g^2*Ip-D*D')\C);
 
       ## set up symplectic generalized eigenvalue problem per Iglesias & Glover
-      s1 = [Ak , zeros(nz) ; -Ck, In ];
-      s2 = [In, -(B/Rg)*B' ; zeros(nz) , Ak' ];
+      s1 = [Ak , zeros(nz); -Ck, In];
+      s2 = [In, -(B/Rg)*B'; zeros(nz), Ak'];
 
       ## guard against roundoff again: zero out extremely small values
       ## prior to balancing
       s1 = s1 .* (abs(s1) > ptol*norm(s1,"inf"));
       s2 = s2 .* (abs(s2) > ptol*norm(s2,"inf"));
-      [cc,dd,s1,s2] = balance(s1,s2);
-      [qza,qzb,zz,pls] = qz(s1,s2,"S"); # ordered qz decomposition
-      eigerr = abs(abs(pls)-1);
-      normH = norm([s1,s2]);
+      [cc, dd, s1, s2] = balance (s1, s2);
+      [qza, qzb, zz, pls] = qz (s1, s2, "S"); # ordered qz decomposition
+      eigerr = abs (abs(pls)-1);
+      normH = norm ([s1, s2]);
       Hb = [s1, s2];
 
       ## check R - B' X B condition (Iglesias and Glover's paper)
       X = zz((nz+1):(2*nz),1:nz)/zz(1:nz,1:nz);
-      dcondfailed = min(real( eig(Rg - B'*X*B)) < ptol);
+      dcondfailed = min (real (eig (Rg - B'*X*B)) < ptol);
     else
       Rinv = inv(g*g*Im - (D' * D));
-      H = [A + B*Rinv*D'*C,        B*Rinv*B'; ...
+      H = [A + B*Rinv*D'*C,        B*Rinv*B';
            -C'*(Ip + D*Rinv*D')*C, -(A + B*Rinv*D'*C)'];
       ## guard against roundoff: zero out extremely small values prior
       ## to balancing
-      H = H .* (abs(H) > ptol*norm(H,"inf"));
-      [DD,Hb] = balance(H);
-      pls = eig(Hb);
-      eigerr = abs(real(pls));
-      normH = norm(H);
+      H = H .* (abs (H) > ptol * norm (H, "inf"));
+      [DD, Hb] = balance (H);
+      pls = eig (Hb);
+      eigerr = abs (real (pls));
+      normH = norm (H);
       dcondfailed = 0;          # digital condition; doesn't apply here
     endif
-    if( (min(eigerr) <= ptol * normH) | dcondfailed)
+    if ((min (eigerr) <= ptol * normH) | dcondfailed)
       gmin = g;
     else
       gmax = g;