7017
|
1 ## Copyright (C) 1996, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, |
|
2 ## 2007 Auburn University. All rights reserved. |
3430
|
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. |
3430
|
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. |
3430
|
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/>. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
5016
|
21 ## @deftypefn {Function File} {@var{sys} =} sysgroup (@var{asys}, @var{bsys}) |
|
22 ## Combines two systems into a single system. |
3430
|
23 ## |
|
24 ## @strong{Inputs} |
5016
|
25 ## @table @var |
|
26 ## @item asys |
|
27 ## @itemx bsys |
|
28 ## System data structures. |
|
29 ## @end table |
3430
|
30 ## |
5016
|
31 ## @strong{Output} |
|
32 ## @table @var |
|
33 ## @item sys |
3502
|
34 ## @math{sys = @r{block diag}(asys,bsys)} |
5016
|
35 ## @end table |
3430
|
36 ## @example |
|
37 ## @group |
|
38 ## __________________ |
|
39 ## | ________ | |
3502
|
40 ## u1 ----->|--> | asys |--->|----> y1 |
3430
|
41 ## | -------- | |
|
42 ## | ________ | |
3502
|
43 ## u2 ----->|--> | bsys |--->|----> y2 |
3430
|
44 ## | -------- | |
|
45 ## ------------------ |
|
46 ## Ksys |
|
47 ## @end group |
|
48 ## @end example |
|
49 ## The function also rearranges the internal state-space realization of @var{sys} |
5016
|
50 ## so that the continuous states come first and the discrete states come last. |
3430
|
51 ## If there are duplicate names, the second name has a unique suffix appended |
|
52 ## on to the end of the name. |
|
53 ## @end deftypefn |
|
54 |
|
55 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
56 ## Created: August 1995 |
|
57 ## modified by John Ingram July 1996 |
|
58 ## A. S. Hodel: modified for variable number of arguments 1999 |
|
59 |
3979
|
60 function sys = sysgroup (varargin) |
3430
|
61 |
7135
|
62 if (nargin < 1) |
6046
|
63 print_usage (); |
5568
|
64 endif |
3430
|
65 |
5568
|
66 ## collect all arguments |
|
67 arglist = {}; |
7135
|
68 for kk = 1:nargin |
5568
|
69 arglist(kk) = varargin{kk}; |
7135
|
70 if (! isstruct (arglist{kk})) |
|
71 error ("sysgroup: argument %d is not a data structure", kk); |
5568
|
72 endif |
|
73 endfor |
4460
|
74 |
7135
|
75 if (nargin == 2) |
5568
|
76 ## the usual case; group the two systems together |
|
77 Asys = arglist{1}; |
|
78 Bsys = arglist{2}; |
4460
|
79 |
5568
|
80 ## extract information from Asys, Bsys to consruct sys |
7135
|
81 Asys = sysupdate (Asys, "ss"); |
|
82 Bsys = sysupdate (Bsys, "ss"); |
|
83 [n1, nz1, m1, p1] = sysdimensions (Asys); |
|
84 [n2, nz2, m2, p2] = sysdimensions (Bsys); |
|
85 [Aa, Ab, Ac, Ad, Atsam, An, Anz, Ast, Ain, Aout, Ayd] = sys2ss (Asys); |
|
86 [Ba, Bb, Bc, Bd, Btsam, Bn, Bnz, Bst, Bin, Bout, Byd] = sys2ss (Bsys); |
5568
|
87 nA = An + Anz; |
|
88 nB = Bn + Bnz; |
4460
|
89 |
7135
|
90 if (p1*m1*p2*m2 == 0) |
|
91 error ("sysgroup: argument lacks inputs and/or outputs"); |
4460
|
92 |
7135
|
93 elseif (Atsam + Btsam > 0 && Atsam * Btsam == 0) |
|
94 warning ("sysgroup: creating combination of continuous and discrete systems") |
4460
|
95 |
7135
|
96 elseif (Atsam != Btsam) |
|
97 error ("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
5568
|
98 endif |
|
99 |
7135
|
100 if (nA*nB > 0) |
|
101 A12 = zeros (nA, nB); |
5568
|
102 else |
|
103 A12 = []; |
|
104 endif |
7135
|
105 A = [Aa, A12; A12', Ba]; |
5568
|
106 |
7135
|
107 if (nA*m2 > 0) |
|
108 B12 = zeros (nA, m2); |
5568
|
109 else |
|
110 B12 = []; |
|
111 endif |
7135
|
112 if (nB*m1 > 0) |
|
113 B21 = zeros (nB, m1); |
5568
|
114 else |
|
115 B21 = []; |
|
116 endif |
7135
|
117 if (isempty(Ab)) |
5568
|
118 Ab = []; |
|
119 endif |
7135
|
120 if (isempty (Bb)) |
5568
|
121 Bb = []; |
|
122 endif |
|
123 B = [Ab, B12; B21, Bb]; |
|
124 |
7135
|
125 if (p1*nB > 0) |
|
126 C12 = zeros (p1, nB); |
5568
|
127 else |
|
128 C12 = []; |
|
129 endif |
7135
|
130 if (p2*nA > 0) |
|
131 C21 = zeros (p2, nA); |
5568
|
132 else |
|
133 C21 = []; |
|
134 endif |
7135
|
135 C = [Ac, C12; C21, Bc]; |
3430
|
136 |
7135
|
137 if (p1*m2 > 0) |
|
138 D12 = zeros (p1, m2); |
5568
|
139 else |
|
140 D12 = []; |
|
141 endif |
7135
|
142 if (p2*m1 > 0) |
|
143 D21 = zeros (p2, m1); |
5568
|
144 else |
|
145 D21 = []; |
|
146 endif |
|
147 D = [Ad, D12; D21, Bd]; |
7135
|
148 tsam = max (Atsam, Btsam); |
5568
|
149 |
|
150 ## construct combined signal names; stnames must check for pure gain blocks |
7135
|
151 if (isempty (Ast)) |
|
152 stname = Bst; |
|
153 elseif (isempty (Bst)) |
|
154 stname = Ast; |
5568
|
155 else |
7135
|
156 stname= __sysconcat__ (Ast, Bst); |
5568
|
157 endif |
7135
|
158 inname = __sysconcat__ (Ain, Bin); |
|
159 outname = __sysconcat__ (Aout, Bout); |
4460
|
160 |
7007
|
161 ## Sort states into continuous first, then discrete |
7135
|
162 dstates = ones (1, (nA+nB)); |
|
163 if (An) |
|
164 dstates(1:(An)) = zeros (1, An); |
5568
|
165 endif |
7135
|
166 if (Bn) |
|
167 dstates((nA+1):(nA+Bn)) = zeros (1, Bn); |
5568
|
168 endif |
7135
|
169 [tmp, pv] = sort (dstates); |
5568
|
170 A = A(pv,pv); |
|
171 B = B(pv,:); |
|
172 C = C(:,pv); |
7135
|
173 stname = stname (pv); |
4460
|
174 |
5568
|
175 ## check for duplicate signal names |
|
176 inname = __sysgroupn__ (inname, "input"); |
|
177 stname = __sysgroupn__ (stname, "state"); |
|
178 outname = __sysgroupn__ (outname, "output"); |
4460
|
179 |
5568
|
180 ## mark discrete outputs |
7135
|
181 outlist = find ([Ayd, Byd]); |
4460
|
182 |
5568
|
183 ## build new system |
7135
|
184 sys = ss (A, B, C, D, tsam, An+Bn, Anz+Bnz, stname, inname, outname); |
4460
|
185 |
5568
|
186 else |
|
187 ## multiple systems (or a single system); combine together one by one |
|
188 sys = arglist{1}; |
7135
|
189 for kk = 2:length(arglist) |
|
190 printf ("sysgroup: kk=%d\n", kk); |
|
191 sys = sysgroup (sys, arglist{kk}); |
5568
|
192 endfor |
|
193 endif |
3430
|
194 |
|
195 endfunction |