annotate scripts/control/is_controllable.m @ 3228:dbcc24961c44

[project @ 1998-12-09 18:42:12 by jwe]
author jwe
date Wed, 09 Dec 1998 18:42:13 +0000
parents ba1c7cdc6090
children 28aba52a2368
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
1 # Copyright (C) 1993, 1994, 1995 John W. Eaton
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
2 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
3 # This file is part of Octave.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
4 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
6 # under the terms of the GNU General Public License as published by the
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
8 # later version.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
9 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
13 # for more details.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
14 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
15 # You should have received a copy of the GNU General Public License
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
18
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
19 function [retval,U] = is_controllable (a, b, tol)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
20 # [retval, U] = is_controllable (a, b {,tol})
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
21 # = is_controllable (sys{, tol})
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
22 # Returns retval=1 if the system sys or the pair (a, b) is controllable
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
23 # 0 if not.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
24 # U is an orthogonal basis of the controllable subspace.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
25 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
26 # Controllability is determined by applying Arnoldi iteration with
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
27 # complete re-orthogonalization to obtain an orthogonal basis of the
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
28 # Krylov subspace.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
29 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
30 # span ([b,a*b,...,a^ b]).
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
31 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
32 # tol is a roundoff paramter, set to 10*eps if omitted.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
33 #
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
34 # See also: size, rows, columns, length, is_matrix, is_scalar, is_vector
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
35 # is_observable, is_stabilizable, is_detectable, krylov, krylovb
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
36
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
37 # Written by A. S. Hodel (scotte@eng.auburn.edu) August, 1993.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
38 # Updated by A. S. Hodel (scotte@eng.auburn.edu) Aubust, 1995 to use krylovb
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
39 # Updated by John Ingram (ingraje@eng.auburn.edu) July, 1996 for packed systems
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
40 # $Revision: 1.15 $
56
3cccff82b7a6 [project @ 1993-08-11 21:49:22 by jwe]
jwe
parents: 26
diff changeset
41
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
42 deftol = 1; # assume default tolerance
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
43 if(nargin < 1 | nargin > 3)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
44 usage("[retval,U] = %s\n\t%s", "is_controllable(a {, b ,tol})", ...
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
45 "is_controllable(sys{,tol})");
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
46 elseif(is_struct(a))
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
47 # system structure passed.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
48 sys = sysupdate(a,"ss");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
49 [a,bs] = sys2ss(sys);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
50 if(nargin > 2)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
51 usage("[retval,U] = is_controllable(sys{,tol})");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
52 elseif(nargin == 2)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
53 tol = b; % get tolerance
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
54 deftol = 0;
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
55 endif
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
56 b = bs;
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
57 else
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
58 # a,b arguments sent directly.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
59 if(nargin < 2)
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
60 usage("[retval,U] = is_controllable(a {, b ,tol})");
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
61 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
62 deftol = 1;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
63 endif
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
64 endif
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
65
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
66 # check for default tolerance
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
67 if(deftol) tol = 1000*eps; endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
68
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
69 # check tol dimensions
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
70 if( !is_scalar(tol) )
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
71 error("is_controllable: tol(%dx%d) must be a scalar", ...
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
72 rows(tol),columns(tol));
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
73 elseif( !is_sample(tol) )
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
74 error("is_controllable: tol=%e must be positive",tol);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
75 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
76
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
77 # check dimensions compatibility
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
78 n = is_square (a);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
79 [nr, nc] = size (b);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
80
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
81 if (n == 0 | n != nr | nc == 0)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
82 warning("is_controllable: a=(%dx%d), b(%dx%d)",rows(a),columns(a),nr,nc);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
83 retval = 0;
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
84 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
85 # call block-krylov subspace routine to get an orthogonal basis
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
86 # of the controllable subspace.
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
87 if(nc == 1)
3228
dbcc24961c44 [project @ 1998-12-09 18:42:12 by jwe]
jwe
parents: 3213
diff changeset
88 [U,H,Ucols] = krylov(a,b,n,tol,1);
3213
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
89 U = U(:,1:Ucols);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
90 else
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
91 [U,Ucols] = krylovb(a,b,n,tol);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
92 U = U(:,1:Ucols);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
93 endif
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
94
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
95 retval = (Ucols == n);
ba1c7cdc6090 [project @ 1998-11-06 16:15:36 by jwe]
jwe
parents: 2847
diff changeset
96 endif
26
e90ea9cbd4de [project @ 1993-08-10 20:56:55 by jwe]
jwe
parents:
diff changeset
97 endfunction