7017
|
1 ## Copyright (C) 1997, 2000, 2002, 2004, 2005, 2006, 2007 Kai P. Mueller |
3432
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3432
|
9 ## |
7016
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
3432
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3432
|
18 |
|
19 ## -*- texinfo -*- |
3501
|
20 ## @deftypefn {Function File} {} ctrb (@var{sys}, @var{b}) |
3502
|
21 ## @deftypefnx {Function File} {} ctrb (@var{a}, @var{b}) |
5016
|
22 ## Build controllability matrix: |
|
23 ## @iftex |
|
24 ## @tex |
|
25 ## $$ Q_s = [ B AB A^2B \ldots A^{n-1}B ] $$ |
|
26 ## @end tex |
|
27 ## @end iftex |
|
28 ## @ifinfo |
3432
|
29 ## @example |
|
30 ## 2 n-1 |
|
31 ## Qs = [ B AB A B ... A B ] |
|
32 ## @end example |
5016
|
33 ## @end ifinfo |
3432
|
34 ## |
3502
|
35 ## of a system data structure or the pair (@var{a}, @var{b}). |
3432
|
36 ## |
5016
|
37 ## @command{ctrb} forms the controllability matrix. |
|
38 ## The numerical properties of @command{is_controllable} |
3432
|
39 ## are much better for controllability tests. |
|
40 ## @end deftypefn |
|
41 |
|
42 ## Author: Kai P. Mueller <mueller@ifr.ing.tu-bs.de> |
|
43 ## Created: November 4, 1997 |
|
44 ## based on is_controllable.m of Scottedward Hodel |
|
45 |
|
46 function Qs = ctrb (sys, b) |
|
47 |
|
48 if (nargin == 2) |
|
49 a = sys; |
7126
|
50 elseif (nargin == 1 && isstruct (sys)) |
|
51 sysupdate (sys, "ss"); |
|
52 [a, b] = sys2ss (sys); |
3432
|
53 else |
6046
|
54 print_usage (); |
3432
|
55 endif |
|
56 |
7126
|
57 if (! is_abcd (a, b)) |
3432
|
58 Qs = []; |
|
59 else |
|
60 ## no need to check dimensions, we trust is_abcd(). |
7126
|
61 [na, ma] = size (a); |
3432
|
62 ## using imb avoids name conflict with the "mb" function |
7126
|
63 [inb, imb] = size (b); |
|
64 Qs = zeros (na, ma*imb); |
3432
|
65 for i = 1:na |
7126
|
66 Qs(:,(i-1)*imb+1:i*imb) = b; |
3432
|
67 b = a * b; |
|
68 endfor |
|
69 endif |
|
70 endfunction |