comparison scripts/control/is_controllable.m @ 3213:ba1c7cdc6090

[project @ 1998-11-06 16:15:36 by jwe]
author jwe
date Fri, 06 Nov 1998 16:16:31 +0000
parents 8b262e771614
children dbcc24961c44
comparison
equal deleted inserted replaced
3212:bf61c443a366 3213:ba1c7cdc6090
1 ## Copyright (C) 1996, 1997 John W. Eaton 1 # Copyright (C) 1993, 1994, 1995 John W. Eaton
2 ## 2 #
3 ## This file is part of Octave. 3 # This file is part of Octave.
4 ## 4 #
5 ## Octave is free software; you can redistribute it and/or modify it 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 6 # under the terms of the GNU General Public License as published by the
7 ## the Free Software Foundation; either version 2, or (at your option) 7 # Free Software Foundation; either version 2, or (at your option) any
8 ## any later version. 8 # later version.
9 ## 9 #
10 ## Octave is distributed in the hope that it will be useful, but 10 # Octave is distributed in the hope that it will be useful, but WITHOUT
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 ## General Public License for more details. 13 # for more details.
14 ## 14 #
15 ## You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, write to the Free 16 # along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA 17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 ## 02111-1307, USA.
19 18
20 ## Usage: is_controllable (a, b {,tol}) 19 function [retval,U] = is_controllable (a, b, tol)
21 ## 20 # [retval, U] = is_controllable (a, b {,tol})
22 ## Returns 1 if the pair (a, b) is controllable, or 0 if not. 21 # = is_controllable (sys{, tol})
23 ## 22 # Returns retval=1 if the system sys or the pair (a, b) is controllable
24 ## See also: size, rows, columns, length, is_matrix, is_scalar, is_vector 23 # 0 if not.
25 ## 24 # U is an orthogonal basis of the controllable subspace.
26 ## This should really use the method below, but I'm being lazy for now: 25 #
27 ## 26 # Controllability is determined by applying Arnoldi iteration with
28 ## Controllability is determined by applying Arnoldi iteration with 27 # complete re-orthogonalization to obtain an orthogonal basis of the
29 ## complete re-orthogonalization to obtain an orthogonal basis of the 28 # Krylov subspace.
30 ## Krylov subspace. 29 #
31 ## 30 # span ([b,a*b,...,a^ b]).
32 ## (FIX ME... The Krylov subspace approach is not done yet!) 31 #
33 ## n-1 32 # tol is a roundoff paramter, set to 10*eps if omitted.
34 ## span ([b,a*b,...,a^ b]). 33 #
35 ## 34 # See also: size, rows, columns, length, is_matrix, is_scalar, is_vector
36 ## tol is a roundoff paramter, set to 2*eps if omitted. 35 # is_observable, is_stabilizable, is_detectable, krylov, krylovb
37 36
38 ## Author: A. S. Hodel <scotte@eng.auburn.edu> 37 # Written by A. S. Hodel (scotte@eng.auburn.edu) August, 1993.
39 ## Created: August 1993 38 # Updated by A. S. Hodel (scotte@eng.auburn.edu) Aubust, 1995 to use krylovb
40 ## Adapted-By: jwe 39 # Updated by John Ingram (ingraje@eng.auburn.edu) July, 1996 for packed systems
40 # SYS_INTERNAL accesses members of packed system structure
41 # $Revision: 1.14 $
41 42
42 function retval = is_controllable (a, b, tol) 43 deftol = 1; # assume default tolerance
43 44 if(nargin < 1 | nargin > 3)
44 if (nargin == 2 || nargin == 3) 45 usage(sprintf("[retval,U] = %s\n\t%s", "is_controllable(a {, b ,tol})", ...
45 46 "is_controllable(sys{,tol})"));
46 n = is_square (a); 47 elseif(is_struct(a))
47 [nr, nc] = size (b); 48 # system structure passed.
48 49 sys = sysupdate(a,"ss");
49 if (n == 0 || n != nr || nc == 0) 50 [a,bs] = sys2ss(sys);
50 retval = 0; 51 if(nargin > 2)
52 usage("[retval,U] = is_controllable(sys{,tol})");
53 elseif(nargin == 2)
54 tol = b; % get tolerance
55 deftol = 0;
56 endif
57 b = bs;
58 else
59 # a,b arguments sent directly.
60 if(nargin < 2)
61 usage("[retval,U] = is_controllable(a {, b ,tol})");
51 else 62 else
52 63 deftol = 1;
53 m = b;
54 tmp = b;
55 for ii = 1:(n-1)
56 tmp = a * tmp;
57 m = [m, tmp];
58 endfor
59
60 ## If n is of any significant size, m will be low rank, so be careful!
61
62 if (nargin == 3)
63 if (is_scalar (tol))
64 retval = (rank (m, tol) == n);
65 else
66 error ("is_controllable: tol must be a scalar");
67 endif
68 else
69 retval = (rank (m) == n);
70 endif
71 endif 64 endif
72 else
73 usage ("is_controllable (a, b)");
74 endif 65 endif
75 66
67 # check for default tolerance
68 if(deftol) tol = 1000*eps; endif
69
70 # check tol dimensions
71 if( !is_sample(tol) )
72 error("is_controllable: tol must be a positive scalar!");
73 endif
74
75 # check dimensions compatibility
76 n = is_square (a);
77 [nr, nc] = size (b);
78
79 if (n == 0 | n != nr | nc == 0)
80 warning(["is_controllable: a=(",num2str(rows(a)),"x", ...
81 num2str(columns(a)),"), b=(",num2str(nr),"x",num2str(nc),")"])
82 retval = 0;
83 else
84 # call block-krylov subspace routine to get an orthogonal basis
85 # of the controllable subspace.
86 if(nc == 1)
87 [U,H,Ucols] = krylov(a,b,n,tol);
88 U = U(:,1:Ucols);
89 else
90 [U,Ucols] = krylovb(a,b,n,tol);
91 U = U(:,1:Ucols);
92 endif
93
94 retval = (Ucols == n);
95 endif
76 endfunction 96 endfunction