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 |
5568
|
62 if(nargin < 1) |
6046
|
63 print_usage (); |
5568
|
64 endif |
3430
|
65 |
5568
|
66 ## collect all arguments |
|
67 arglist = {}; |
|
68 for kk=1:nargin |
|
69 arglist(kk) = varargin{kk}; |
|
70 if(!isstruct(arglist{kk})) |
4460
|
71 error("sysgroup: argument %d is not a data structure",kk); |
5568
|
72 endif |
|
73 endfor |
4460
|
74 |
5568
|
75 if(nargin == 2) |
|
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 |
|
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); |
|
87 nA = An + Anz; |
|
88 nB = Bn + Bnz; |
4460
|
89 |
5568
|
90 if(p1*m1*p2*m2 == 0) |
4460
|
91 error("sysgroup: argument lacks inputs and/or outputs"); |
|
92 |
5568
|
93 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
4460
|
94 warning("sysgroup: creating combination of continuous and discrete systems") |
|
95 |
5568
|
96 elseif(Atsam != Btsam) |
4460
|
97 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
5568
|
98 endif |
|
99 |
|
100 if(nA*nB > 0) |
|
101 A12 = zeros(nA,nB); |
|
102 else |
|
103 A12 = []; |
|
104 endif |
|
105 A = [Aa,A12; A12', Ba]; |
|
106 |
|
107 if(nA*m2 > 0) |
|
108 B12 = zeros(nA,m2); |
|
109 else |
|
110 B12 = []; |
|
111 endif |
|
112 if(nB*m1 > 0) |
|
113 B21 = zeros(nB,m1); |
|
114 else |
|
115 B21 = []; |
|
116 endif |
|
117 if(isempty(Ab)) |
|
118 Ab = []; |
|
119 endif |
|
120 if(isempty(Bb)) |
|
121 Bb = []; |
|
122 endif |
|
123 B = [Ab, B12; B21, Bb]; |
|
124 |
|
125 if(p1*nB > 0) |
|
126 C12 = zeros(p1,nB); |
|
127 else |
|
128 C12 = []; |
|
129 endif |
|
130 if(p2*nA > 0) |
|
131 C21 = zeros(p2,nA); |
|
132 else |
|
133 C21 = []; |
|
134 endif |
|
135 C = [Ac, C12; C21,Bc]; |
3430
|
136 |
5568
|
137 if(p1*m2 > 0) |
|
138 D12 = zeros(p1,m2); |
|
139 else |
|
140 D12 = []; |
|
141 endif |
|
142 if(p2*m1 > 0) |
|
143 D21 = zeros(p2,m1); |
|
144 else |
|
145 D21 = []; |
|
146 endif |
|
147 D = [Ad, D12; D21, Bd]; |
|
148 tsam = max(Atsam,Btsam); |
|
149 |
|
150 ## construct combined signal names; stnames must check for pure gain blocks |
|
151 if(isempty(Ast)) |
|
152 stname = Bst; |
|
153 elseif(isempty(Bst)) |
|
154 stname = Ast; |
|
155 else |
|
156 stname= __sysconcat__(Ast,Bst); |
|
157 endif |
|
158 inname = __sysconcat__(Ain,Bin); |
|
159 outname = __sysconcat__(Aout,Bout); |
4460
|
160 |
5568
|
161 ## Sort states into continous first, then discrete |
|
162 dstates = ones(1,(nA+nB)); |
|
163 if(An) |
4460
|
164 dstates(1:(An)) = zeros(1,An); |
5568
|
165 endif |
|
166 if(Bn) |
4460
|
167 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
5568
|
168 endif |
|
169 [tmp,pv] = sort(dstates); |
|
170 A = A(pv,pv); |
|
171 B = B(pv,:); |
|
172 C = C(:,pv); |
|
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 |
|
181 outlist = find([Ayd, Byd]); |
4460
|
182 |
5568
|
183 ## build new system |
|
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}; |
|
189 for kk=2:length(arglist) |
4460
|
190 printf("sysgroup: kk=%d\n",kk); |
4771
|
191 sys = sysgroup(sys,arglist{kk}); |
5568
|
192 endfor |
|
193 endif |
3430
|
194 |
|
195 endfunction |