7017
|
1 ## Copyright (C) 1993, 1994, 1995, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3431
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3431
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3431
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3431
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {[@var{n}, @var{m}, @var{p}] =} abcddim (@var{a}, @var{b}, @var{c}, @var{d}) |
|
22 ## Check for compatibility of the dimensions of the matrices defining |
|
23 ## the linear system |
|
24 ## @iftex |
|
25 ## @tex |
|
26 ## $[A, B, C, D]$ corresponding to |
|
27 ## $$ |
|
28 ## \eqalign{ |
|
29 ## {dx\over dt} &= A x + B u\cr |
|
30 ## y &= C x + D u} |
|
31 ## $$ |
|
32 ## @end tex |
|
33 ## @end iftex |
|
34 ## @ifinfo |
|
35 ## [A, B, C, D] corresponding to |
|
36 ## |
|
37 ## @example |
|
38 ## dx/dt = a x + b u |
|
39 ## y = c x + d u |
|
40 ## @end example |
|
41 ## |
|
42 ## @end ifinfo |
|
43 ## or a similar discrete-time system. |
|
44 ## |
|
45 ## If the matrices are compatibly dimensioned, then @code{abcddim} returns |
|
46 ## |
|
47 ## @table @var |
|
48 ## @item n |
|
49 ## The number of system states. |
|
50 ## |
|
51 ## @item m |
|
52 ## The number of system inputs. |
|
53 ## |
|
54 ## @item p |
|
55 ## The number of system outputs. |
|
56 ## @end table |
|
57 ## |
|
58 ## Otherwise @code{abcddim} returns @var{n} = @var{m} = @var{p} = @minus{}1. |
|
59 ## |
|
60 ## Note: n = 0 (pure gain block) is returned without warning. |
5642
|
61 ## @seealso{is_abcd} |
3431
|
62 ## @end deftypefn |
|
63 |
|
64 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
65 ## Created: August 1993. |
|
66 ## a s hodel: modified to accept pure-gain systems aug 1996 |
|
67 |
|
68 function [n, m, p] = abcddim (a, b, c, d) |
|
69 |
|
70 if (nargin != 4) |
7136
|
71 print_usage (); |
3431
|
72 endif |
|
73 |
|
74 n = m = p = -1; |
|
75 |
3438
|
76 [a, an, am] = __abcddims__ (a); |
|
77 [b, bn, bm] = __abcddims__ (b); |
|
78 [c, cn, cm] = __abcddims__ (c); |
|
79 [d, dn, dm] = __abcddims__ (d); |
3431
|
80 |
7136
|
81 if (! issquare (a) && ! isempty (a)) |
|
82 warning ("abcddim: a is not square (%dx%d)", an, am); |
|
83 return; |
3431
|
84 endif |
|
85 |
7136
|
86 if (bm == 0 && dm == 0) |
|
87 warning ("abcddim: no inputs"); |
3431
|
88 elseif (bn != am) |
7136
|
89 warning ("abcddim: a(%dx%d) and b(%dx%d) are not compatible", |
|
90 an, am, bn, bm); |
|
91 return; |
3431
|
92 endif |
|
93 |
7136
|
94 if (cn == 0 && dn == 0) |
|
95 warning ("abcddim: no outputs"); |
3431
|
96 elseif (cm != an) |
7136
|
97 warning ("abcddim: a(%dx%d) and c(%dx%d) are not compatible", |
|
98 an, am, cn, cm); |
|
99 return; |
3431
|
100 endif |
|
101 |
|
102 have_connections = (bn*cn != 0); |
|
103 |
7136
|
104 if (dn == 0 && have_connections) |
|
105 warning ("abcddim: empty d matrix passed; setting compatibly with b, c"); |
3438
|
106 [d, dn, dm] = __abcddims__ (zeros (cn, bm)); |
3431
|
107 endif |
|
108 |
7136
|
109 if (an > 0) |
|
110 [dn, dm] = size (d); |
|
111 if (cn != dn && have_connections) |
|
112 warning ("abcddim: c(%dx%d) and d(%dx%d) are not compatible", |
|
113 cn, cm, dn, dm); |
|
114 return; |
3431
|
115 endif |
|
116 |
7136
|
117 if (bm != dm && have_connections) |
|
118 warning ("abcddim: b(",num2str(bn),"x",num2str(bm), ... |
|
119 " and d(",num2str(dn),"x",num2str(dm),") are not compatible"); |
|
120 return; |
3431
|
121 endif |
|
122 |
|
123 m = bm; |
|
124 p = cn; |
|
125 else |
7136
|
126 [p, m] = size (d); |
3431
|
127 endif |
|
128 n = an; |
7136
|
129 |
3431
|
130 endfunction |