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