changeset 55:b973bf9a9dba

[project @ 1993-08-11 21:42:23 by jwe]
author jwe
date Wed, 11 Aug 1993 21:42:23 +0000
parents 98eb51c870b2
children 3cccff82b7a6
files scripts/control/are.m
diffstat 1 files changed, 52 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/control/are.m	Wed Aug 11 21:30:43 1993 +0000
+++ b/scripts/control/are.m	Wed Aug 11 21:42:23 1993 +0000
@@ -1,60 +1,65 @@
-function x = are(a,b,c,opt)
+function x = are (a, b, c, opt)
 
+# usage: x = are (a, b, c {,opt})
 #
-# usage: x = are(a,b,c{,opt})
-#
-# solves algebraic riccati equation
+# Solves algebraic riccati equation
 #
-#    a' x + x a - x b x + c = 0
+#   a' x + x a - x b x + c = 0
 #
-# for identically dimensioned square matrices a,b,c.  If b (c) is not square,
-# then the function attempts to use b*b' (c'*c) instead.
+# for identically dimensioned square matrices a, b, c.  If b (c) is not
+# square, then the function attempts to use b * b' (c' * c) instead.
 #
-# opt is an option passed to the eigenvalue balancing routine; default is 'B'
+# opt is an option passed to the eigenvalue balancing routine; default
+# is `B'. 
 #
 # see also: balance
 
-if((nargin == 3) || (nargin == 4))
-  if(nargin==4)
-    if((opt ~= 'N') || (opt ~= 'P') || (opt ~= 'S') || (opt ~= 'B'))
-      printf('warning: are: opt has an illegal value; setting to B');
-      opt = 'B';
+  if (nargin == 3 || nargin == 4)
+    if (nargin == 4)
+      if (! (strcmp (opt, "N") || strcmp (opt, "P") ...
+	     || strcmp (opt, "S") || strcmp (opt, "B") ...
+	     || strcmp (opt, "n") || strcmp (opt, "p") ...
+	     || strcmp (opt, "s") || strcmp (opt, "b")))
+	printf ("warning: are: opt has an illegal value; setting to B");
+	opt = "B";
+      endif
+    else
+      opt = "B";
+    endif
+    if ((n = is_square(a)) == 0)
+      error ("are: a is not square");
+    endif
+
+    if (is_controllable(a,b) == 0)
+      printf("warning: are: a, b are not controllable");
     endif
+    if ((m = is_square (b)) == 0)
+      b = b * b';
+      m = rows (b);
+    endif
+    if (is_observable (a, c) == 0)
+      printf ("warning: are: a,c are not observable");
+    endif
+    if ((p = is_square (c)) == 0)
+      c = c' * c;
+      p = rows (c);
+    endif
+    if (n != m || n != p)
+      error ("are: a, b, c not conformably dimensioned.");
+    endif
+
+# Should check for controllability/observability here
+# use Boley-Golub (Syst. Contr. Letters, 1984) method, not the
+#
+#                     n-1
+# rank ([ B A*B ... A^   *B]) method 
+
+    [u, s] = schur (balance ([a, -b; -c, -a'], opt), "A");
+    n1 = n + 1;
+    n2 = 2 * n;
+    x = u (n1:n2, 1:n) / u (1:n, 1:n);
   else
-    opt = 'B';
-  endif
-  if( (n = is_square(a) ) == 0)
-    error('are: a is not square')
-  endif
-  if(is_controllable(a,b) == 0)
-    printf('warning: are: a,b are not controllable')
-  endif
-  if( (m = is_square(b)) == 0)
-    b = b*b';
-    m = rows(b);
-  endif
-  if(is_observable(a,c) == 0)
-    printf('warning: are: a,c are not observable')
-  endif
-  if( (p = is_square(c)) == 0)
-    c = c'*c;
-    p = rows(c);
-  endif
-  if( (n ~= m) || (n ~= p))
-    error('are: a,b,c not conformably dimensioned.')
+    error("usage: x = are (a, b, c)")
   endif
 
-  # should check for controllability/observability here
-  # use Boley-Golub (Syst. Contr. Letters, 1984) method, not the
-  #                    n-1
-  # rank([ B A*B ... A^   *B]) method 
-  
-  [u,s] = schur(balance([a,-b;-c,-a'],opt),'A');
-  n1=n+1;
-  n2 = 2*n;
-  x = u(n1:n2,1:n)/u(1:n,1:n);
-else
-  error('usage: x = are(a,b,c)')
-endif
-
 endfunction