]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/__ss_dim__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / __ss_dim__.m
1 ## Copyright (C) 2009, 2010   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## Number of outputs (p), inputs (m) and states (n) of state space matrices.
20 ## For internal use only.
21
22 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
23 ## Created: September 2009
24 ## Version: 0.2
25
26 function [p, m, n] = __ss_dim__ (a, b, c, d, e = [])
27
28   ## TODO: create oct-file?
29
30   if (! is_real_matrix (a, b, c, d, e))
31     error ("ss: system matrices must be real");
32   endif
33
34   [arows, acols] = size (a);
35   [brows, bcols] = size (b);
36   [crows, ccols] = size (c);
37   [drows, dcols] = size (d);
38
39   m = bcols;  # = dcols
40   n = arows;  # = acols
41   p = crows;  # = drows
42
43   if (arows != acols)
44     error ("ss: system matrix a(%dx%d) is not square", arows, acols);
45   endif
46
47   if (brows != arows)
48     error ("ss: system matrices a(%dx%d) and b(%dx%d) are incompatible",
49             arows, acols, brows, bcols);
50   endif
51
52   if (ccols != acols)
53     error ("ss: system matrices a(%dx%d) and c(%dx%d) are incompatible",
54             arows, acols, crows, ccols);
55   endif
56
57   if (bcols != dcols)
58     error ("ss: system matrices b(%dx%d) and d(%dx%d) are incompatible",
59             brows, bcols, drows, dcols);
60   endif
61
62   if (crows != drows)
63     error ("ss: system matrices c(%dx%d) and d(%dx%d) are incompatible",
64             crows, ccols, drows, dcols);
65   endif
66
67   if (! isempty (e) && ! size_equal (e, a))
68     error ("ss: system matrices a(%dx%d) and e(%dx%d) are incompatible",
69             arows, acols, rows (e), columns (e));
70   endif
71
72 endfunction