[Octave-cvsupdate] SF.net SVN: octave:[6372]
trunk/octave-forge/extra/control-oo/inst/control/ are.m
From: <par...@us...> - 2009-10-24 16:49:49
|
Revision: 6372 http://octave.svn.sourceforge.net/octave/?rev=6372&view=rev Author: paramaniac Date: 2009-10-24 16:49:39 +0000 (Sat, 24 Oct 2009) Log Message: ----------- control-oo: simplify are Modified Paths: -------------- trunk/octave-forge/extra/control-oo/inst/control/are.m Modified: trunk/octave-forge/extra/control-oo/inst/control/are.m =================================================================== --- trunk/octave-forge/extra/control-oo/inst/control/are.m 2009-10-24 16:46:56 UTC (rev 6371) +++ trunk/octave-forge/extra/control-oo/inst/control/are.m 2009-10-24 16:49:39 UTC (rev 6372) @@ -71,57 +71,71 @@ function x = are (a, b, c, opt) - if (nargin == 3 || nargin == 4) - if (nargin == 4) - if (! (ischar (opt) - && (strcmp (opt, "N") || strcmp (opt, "P") - || strcmp (opt, "S") || strcmp (opt, "B") - || strcmp (opt, "n") || strcmp (opt, "p") - || strcmp (opt, "s") || strcmp (opt, "b")))) - warning ("are: opt has an invalid value; setting to B"); - opt = "B"; - endif - else + if (nargin < 3 || nargin > 4) + print_usage (); + endif + + if (nargin == 4) + if (! ischar (opt)) + warning ("are: invalid argument opt, setting to ""B"""); opt = "B"; endif - if ((n = issquare(a)) == 0) - error ("are: a is not square"); - endif - if (isctrb (a, b) == 0) - warning ("are: a, b are not controllable"); + opt = upper (opt); + + if (opt != "B" && opt != N && opt != "P" && opt != "S") + warning ("are: opt has invalid value ""%s""; setting to ""B""", opt); + opt = "B"; endif - if ((m = issquare (b)) == 0) - b = b * b'; - m = rows (b); - endif - if (isobsv (a, c) == 0) - warning ("are: a,c are not observable"); - endif - if ((p = issquare (c)) == 0) - c = c' * c; - p = rows (c); - endif - if (n != m || n != p) - error ("are: a, b, c not conformably dimensioned."); - endif + else + opt = "B"; + 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 + n = issquare (a); + m = issquare (b); + p = issquare (c); - ## RE: isctrb, isobsv use arnoldi/krylov + if (! n) + error ("are: matrix a is not square"); + endif - [d, h] = balance ([a, -b; -c, -a'], opt); - [u, s] = schur (h, "A"); - u = d * u; - n1 = n + 1; - n2 = 2 * n; - x = u (n1:n2, 1:n) / u (1:n, 1:n); - else - print_usage (); + if (! isctrb (a, b)) + warning ("are: matrices a and b are not controllable"); endif + if (! m) + b = b * b'; + m = rows (b); + endif + + if (! isobsv (a, c)) + warning ("are: matrices a and c are not observable"); + endif + + if (! p) + c = c' * c; + p = rows (c); + endif + + if (n != m || n != p) + error ("are: matrices a, b and 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 + + ## RE: isctrb, isobsv use Arnoldi/Krylov + + [d, h] = balance ([a, -b; -c, -a'], opt); + [u, s] = schur (h, "A"); + + u = d * u; + n1 = n + 1; + n2 = 2 * n; + + x = u (n1:n2, 1:n) / u (1:n, 1:n); + endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |