1 ## Copyright (C) 2009, 2010, 2012 Lukas F. Reichlin
2 ## Copyright (C) 2009 Luca Favatella <slackydeb@gmail.com>
4 ## This file is part of LTI Syncope.
6 ## LTI Syncope is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
11 ## LTI Syncope is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{co} =} ctrb (@var{sys})
21 ## @deftypefnx {Function File} {@var{co} =} ctrb (@var{a}, @var{b})
22 ## Return controllability matrix.
29 ## State transition matrix (n-by-n).
31 ## Input matrix (n-by-m).
37 ## Controllability matrix.
43 ## $$ C_o = [ B \\ \\ AB \\ \\ A^2B \\ \\ldots \\ A^{n-1}B ] $$
49 ## Co = [ B AB A B ... A B ]
54 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
55 ## Created: October 2009
58 function co = ctrb (a, b)
60 if (nargin == 1) # ctrb (sys)
62 error ("ctrb: argument must be an lti system");
65 elseif (nargin == 2) # ctrb (a, b)
66 if (! is_real_square_matrix (a) || ! is_real_matrix (b) || rows (a) != rows (b))
67 error ("ctrb: invalid arguments (a, b)");
73 n = rows (a); # number of states
74 k = 0:n-1; # exponents for a
76 tmp = arrayfun (@(x) a^x*b, k, "uniformoutput", false);
78 co = horzcat (tmp{:});
83 %!assert (ctrb ([1, 0; 0, -0.5], [8; 8]), [8, 8; 8, -4]);