]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/ctrb.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / ctrb.m
1 ## Copyright (C) 2009, 2010, 2012   Lukas F. Reichlin
2 ## Copyright (C) 2009 Luca Favatella <slackydeb@gmail.com>
3 ##
4 ## This file is part of LTI Syncope.
5 ##
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.
10 ##
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.
15 ##
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/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{co} =} ctrb (@var{sys})
21 ## @deftypefnx {Function File} {@var{co} =} ctrb (@var{a}, @var{b})
22 ## Return controllability matrix.
23 ##
24 ## @strong{Inputs}
25 ## @table @var
26 ## @item sys
27 ## LTI model.
28 ## @item a
29 ## State transition matrix (n-by-n).
30 ## @item b
31 ## Input matrix (n-by-m).
32 ## @end table
33 ##
34 ## @strong{Outputs}
35 ## @table @var
36 ## @item co
37 ## Controllability matrix.
38 ## @end table
39 ##
40 ## @strong{Equation}
41 ## @iftex
42 ## @tex
43 ## $$ C_o = [ B \\ \\ AB \\ \\ A^2B \\ \\ldots \\ A^{n-1}B ] $$
44 ## @end tex
45 ## @end iftex
46 ## @ifnottex
47 ## @example
48 ##              2       n-1
49 ## Co = [ B AB A B ... A   B ]
50 ## @end example
51 ## @end ifnottex
52 ## @end deftypefn
53
54 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
55 ## Created: October 2009
56 ## Version: 0.3
57
58 function co = ctrb (a, b)
59
60   if (nargin == 1)       # ctrb (sys)
61     if (! isa (a, "lti"))
62       error ("ctrb: argument must be an lti system");
63     endif
64     [a, b] = ssdata (a);
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)");
68     endif
69   else
70     print_usage ();
71   endif
72
73   n = rows (a);          # number of states
74   k = 0:n-1;             # exponents for a
75
76   tmp = arrayfun (@(x) a^x*b, k, "uniformoutput", false);
77
78   co = horzcat (tmp{:});
79
80 endfunction
81
82
83 %!assert (ctrb ([1, 0; 0, -0.5], [8; 8]), [8, 8; 8, -4]);