3430
|
1 ## Copyright (C) 1996, 1998, 1999 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
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 |
4460
|
62 save_warn_empty_list_elements = warn_empty_list_elements; |
|
63 unwind_protect |
|
64 warn_empty_list_elements = 0; |
3430
|
65 |
4460
|
66 if(nargin < 1) |
|
67 usage("sys = sysgroup(Asys{,Bsys,...})"); |
3430
|
68 endif |
|
69 |
4460
|
70 ## collect all arguments |
4771
|
71 arglist = {}; |
4460
|
72 for kk=1:nargin |
|
73 arglist(kk) = varargin{kk}; |
4771
|
74 if(!isstruct(arglist{kk})) |
4460
|
75 error("sysgroup: argument %d is not a data structure",kk); |
|
76 endif |
|
77 endfor |
|
78 |
|
79 if(nargin == 2) |
|
80 ## the usual case; group the two systems together |
4771
|
81 Asys = arglist{1}; |
|
82 Bsys = arglist{2}; |
4460
|
83 |
|
84 ## extract information from Asys, Bsys to consruct sys |
|
85 Asys = sysupdate(Asys,"ss"); |
|
86 Bsys = sysupdate(Bsys,"ss"); |
|
87 [n1,nz1,m1,p1] = sysdimensions(Asys); |
|
88 [n2,nz2,m2,p2] = sysdimensions(Bsys); |
|
89 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys); |
|
90 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys); |
|
91 nA = An + Anz; |
|
92 nB = Bn + Bnz; |
|
93 |
|
94 if(p1*m1*p2*m2 == 0) |
|
95 error("sysgroup: argument lacks inputs and/or outputs"); |
|
96 |
|
97 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
|
98 warning("sysgroup: creating combination of continuous and discrete systems") |
|
99 |
|
100 elseif(Atsam != Btsam) |
|
101 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
|
102 endif |
3430
|
103 |
4771
|
104 if(nA*nB > 0) |
|
105 A12 = zeros(nA,nB); |
|
106 else |
|
107 A12 = []; |
|
108 endif |
|
109 A = [Aa,A12; A12', Ba]; |
|
110 |
|
111 if(nA*m2 > 0) |
|
112 B12 = zeros(nA,m2); |
|
113 else |
|
114 B12 = []; |
|
115 endif |
|
116 if(nB*m1 > 0) |
|
117 B21 = zeros(nB,m1); |
|
118 else |
|
119 B21 = []; |
|
120 endif |
|
121 if(isempty(Ab)) |
|
122 Ab = []; |
|
123 endif |
|
124 if(isempty(Bb)) |
|
125 Bb = []; |
|
126 endif |
|
127 B = [Ab, B12; B21, Bb]; |
|
128 |
|
129 if(p1*nB > 0) |
|
130 C12 = zeros(p1,nB); |
|
131 else |
|
132 C12 = []; |
|
133 endif |
|
134 if(p2*nA > 0) |
|
135 C21 = zeros(p2,nA); |
|
136 else |
|
137 C21 = []; |
|
138 endif |
|
139 C = [Ac, C12; C21,Bc]; |
|
140 |
|
141 if(p1*m2 > 0) |
|
142 D12 = zeros(p1,m2); |
|
143 else |
|
144 D12 = []; |
|
145 endif |
|
146 if(p2*m1 > 0) |
|
147 D21 = zeros(p2,m1); |
|
148 else |
|
149 D21 = []; |
|
150 endif |
|
151 D = [Ad, D12; D21, Bd]; |
4460
|
152 tsam = max(Atsam,Btsam); |
|
153 |
|
154 ## construct combined signal names; stnames must check for pure gain blocks |
|
155 if(isempty(Ast)) |
|
156 stname = Bst; |
|
157 elseif(isempty(Bst)) |
|
158 stname = Ast; |
|
159 else |
4771
|
160 stname= __sysconcat__(Ast,Bst); |
4460
|
161 endif |
4771
|
162 inname = __sysconcat__(Ain,Bin); |
|
163 outname = __sysconcat__(Aout,Bout); |
4460
|
164 |
|
165 ## Sort states into continous first, then discrete |
|
166 dstates = ones(1,(nA+nB)); |
|
167 if(An) |
|
168 dstates(1:(An)) = zeros(1,An); |
|
169 endif |
|
170 if(Bn) |
|
171 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
|
172 endif |
|
173 [tmp,pv] = sort(dstates); |
|
174 A = A(pv,pv); |
|
175 B = B(pv,:); |
|
176 C = C(:,pv); |
|
177 stname = stname(pv); |
|
178 |
|
179 ## check for duplicate signal names |
|
180 inname = __sysgroupn__ (inname, "input"); |
|
181 stname = __sysgroupn__ (stname, "state"); |
|
182 outname = __sysgroupn__ (outname, "output"); |
|
183 |
|
184 ## mark discrete outputs |
|
185 outlist = find([Ayd, Byd]); |
|
186 |
|
187 ## build new system |
4771
|
188 sys = ss(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
4460
|
189 |
3430
|
190 else |
4460
|
191 ## multiple systems (or a single system); combine together one by one |
4771
|
192 sys = arglist{1}; |
4460
|
193 for kk=2:length(arglist) |
|
194 printf("sysgroup: kk=%d\n",kk); |
4771
|
195 sys = sysgroup(sys,arglist{kk}); |
4460
|
196 endfor |
3430
|
197 endif |
|
198 |
4460
|
199 unwind_protect_cleanup |
|
200 warn_empty_list_elements = save_warn_empty_list_elements; |
|
201 end_unwind_protect |
3430
|
202 |
|
203 endfunction |