3431
|
1 ## Copyright (C) 1998 Kai P. Mueller |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3431
|
9 ## |
7016
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
3431
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3431
|
18 |
|
19 ## -*- texinfo -*- |
3502
|
20 ## @deftypefn {Function File} {} buildssic (@var{clst}, @var{ulst}, @var{olst}, @var{ilst}, @var{s1}, @var{s2}, @var{s3}, @var{s4}, @var{s5}, @var{s6}, @var{s7}, @var{s8}) |
3431
|
21 ## |
|
22 ## Form an arbitrary complex (open or closed loop) system in |
5016
|
23 ## state-space form from several systems. @command{buildssic} can |
|
24 ## easily (despite its cryptic syntax) integrate transfer functions |
3431
|
25 ## from a complex block diagram into a single system with one call. |
|
26 ## This function is especially useful for building open loop |
5016
|
27 ## interconnections for |
|
28 ## @iftex |
|
29 ## @tex |
|
30 ## $ { \cal H }_\infty $ and $ { \cal H }_2 $ |
|
31 ## @end tex |
|
32 ## @end iftex |
|
33 ## @ifinfo |
|
34 ## H-infinity and H-2 |
|
35 ## @end ifinfo |
|
36 ## designs or for closing loops with these controllers. |
3431
|
37 ## |
5016
|
38 ## Although this function is general purpose, the use of @command{sysgroup} |
|
39 ## @command{sysmult}, @command{sysconnect} and the like is recommended for |
3431
|
40 ## standard operations since they can handle mixed discrete and continuous |
|
41 ## systems and also the names of inputs, outputs, and states. |
|
42 ## |
|
43 ## The parameters consist of 4 lists that describe the connections |
5016
|
44 ## outputs and inputs and up to 8 systems @var{s1}--@var{s8}. |
3431
|
45 ## Format of the lists: |
|
46 ## @table @var |
3502
|
47 ## @item clst |
3431
|
48 ## connection list, describes the input signal of |
|
49 ## each system. The maximum number of rows of Clst is |
|
50 ## equal to the sum of all inputs of s1-s8. |
|
51 ## |
|
52 ## Example: |
5016
|
53 ## @code{[1 2 -1; 2 1 0]} means that: new input 1 is old input 1 |
|
54 ## + output 2 - output 1, and new input 2 is old input 2 |
3431
|
55 ## + output 1. The order of rows is arbitrary. |
|
56 ## |
5016
|
57 ## @item ulst |
|
58 ## if not empty the old inputs in vector @var{ulst} will |
3431
|
59 ## be appended to the outputs. You need this if you |
5016
|
60 ## want to ``pull out'' the input of a system. Elements |
|
61 ## are input numbers of @var{s1}--@var{s8}. |
3431
|
62 ## |
5016
|
63 ## @item olst |
7001
|
64 ## output list, specifies the outputs of the resulting |
5016
|
65 ## systems. Elements are output numbers of @var{s1}--@var{s8}. |
|
66 ## The numbers are allowed to be negative and may |
3431
|
67 ## appear in any order. An empty matrix means |
|
68 ## all outputs. |
|
69 ## |
5016
|
70 ## @item ilst |
7001
|
71 ## input list, specifies the inputs of the resulting |
5016
|
72 ## systems. Elements are input numbers of @var{s1}--@var{s8}. |
|
73 ## The numbers are allowed to be negative and may |
3431
|
74 ## appear in any order. An empty matrix means |
|
75 ## all inputs. |
|
76 ## @end table |
|
77 ## |
|
78 ## Example: Very simple closed loop system. |
|
79 ## @example |
|
80 ## @group |
|
81 ## w e +-----+ u +-----+ |
|
82 ## --->o--*-->| K |--*-->| G |--*---> y |
|
83 ## ^ | +-----+ | +-----+ | |
|
84 ## - | | | | |
|
85 ## | | +----------------> u |
|
86 ## | | | |
|
87 ## | +-------------------------|---> e |
|
88 ## | | |
|
89 ## +----------------------------+ |
|
90 ## @end group |
|
91 ## @end example |
|
92 ## |
7001
|
93 ## The closed loop system @var{GW} can be obtained by |
3431
|
94 ## @example |
|
95 ## GW = buildssic([1 2; 2 -1], 2, [1 2 3], 2, G, K); |
|
96 ## @end example |
|
97 ## @table @var |
3502
|
98 ## @item clst |
5016
|
99 ## 1st row: connect input 1 (@var{G}) with output 2 (@var{K}). |
|
100 ## |
|
101 ## 2nd row: connect input 2 (@var{K}) with negative output 1 (@var{G}). |
3502
|
102 ## @item ulst |
5016
|
103 ## Append input of 2 (@var{K}) to the number of outputs. |
3502
|
104 ## @item olst |
5016
|
105 ## Outputs are output of 1 (@var{G}), 2 (@var{K}) and |
|
106 ## appended output 3 (from @var{ulst}). |
3502
|
107 ## @item ilst |
5016
|
108 ## The only input is 2 (@var{K}). |
3431
|
109 ## @end table |
|
110 ## |
|
111 ## Here is a real example: |
|
112 ## @example |
|
113 ## @group |
|
114 ## +----+ |
|
115 ## -------------------->| W1 |---> v1 |
|
116 ## z | +----+ |
5016
|
117 ## ----|-------------+ |
|
118 ## | | |
3431
|
119 ## | +---+ v +----+ |
|
120 ## *--->| G |--->O--*-->| W2 |---> v2 |
|
121 ## | +---+ | +----+ |
|
122 ## | | |
|
123 ## | v |
|
124 ## u y |
|
125 ## @end group |
|
126 ## @end example |
5016
|
127 ## @iftex |
|
128 ## @tex |
|
129 ## $$ { \rm min } \Vert GW_{vz} \Vert _\infty $$ |
|
130 ## @end tex |
|
131 ## @end iftex |
|
132 ## @ifinfo |
|
133 ## @example |
|
134 ## min || GW || |
|
135 ## vz infty |
|
136 ## @end example |
|
137 ## @end ifinfo |
3431
|
138 ## |
5016
|
139 ## The closed loop system @var{GW} |
|
140 ## @iftex |
|
141 ## @tex |
|
142 ## from $ [z, u]^T $ to $ [v_1, v_2, y]^T $ |
|
143 ## @end tex |
|
144 ## @end iftex |
|
145 ## @ifinfo |
|
146 ## from [z, u]' to [v1, v2, y]' |
|
147 ## @end ifinfo |
|
148 ## can be obtained by (all @acronym{SISO} systems): |
3431
|
149 ## @example |
|
150 ## GW = buildssic([1, 4; 2, 4; 3, 1], 3, [2, 3, 5], |
|
151 ## [3, 4], G, W1, W2, One); |
|
152 ## @end example |
7001
|
153 ## where ``One'' is a unity gain (auxiliary) function with order 0. |
3431
|
154 ## (e.g. @code{One = ugain(1);}) |
|
155 ## @end deftypefn |
|
156 |
|
157 ## Author: Kai P. Mueller <mueller@ifr.ing.tu-bs.de> |
|
158 ## Created: April 1998 |
|
159 |
|
160 function sys = buildssic (Clst, Ulst, Olst, Ilst, s1, s2, s3, s4, s5, s6, s7, s8) |
|
161 |
|
162 if((nargin < 5) || (nargin > 12)) |
6046
|
163 print_usage (); |
3431
|
164 endif |
|
165 if (nargin >= 5) |
4030
|
166 if (!isstruct(s1)) |
3431
|
167 error("---> s1 must be a structed system."); |
|
168 endif |
|
169 s1 = sysupdate(s1, "ss"); |
|
170 [n, nz, m, p] = sysdimensions(s1); |
|
171 if (!n && !nz) |
|
172 error("---> pure static system must not be the first in list."); |
|
173 endif |
|
174 if (n && nz) |
|
175 error("---> cannot handle mixed continuous and discrete systems."); |
|
176 endif |
|
177 D_SYS = (nz > 0); |
|
178 [A,B,C,D,tsam] = sys2ss(s1); |
|
179 nt = n + nz; |
|
180 endif |
|
181 for ii = 6:nargin |
4771
|
182 eval(["mysys = s", num2str(ii-4), ";"]); |
|
183 if (!isstruct(mysys)) |
3431
|
184 error("---> Parameter must be a structed system."); |
|
185 endif |
4771
|
186 mysys = sysupdate(mysys, "ss"); |
|
187 [n1, nz1, m1, p1] = sysdimensions(mysys); |
3431
|
188 if (n1 && nz1) |
|
189 error("---> cannot handle mixed continuous and discrete systems."); |
|
190 endif |
|
191 if (D_SYS) |
|
192 if (n1) |
|
193 error("---> cannot handle mixed cont. and discr. systems."); |
|
194 endif |
4771
|
195 if (tsam != sysgettsam(mysys)) |
3431
|
196 error("---> sampling time of all systems must match."); |
|
197 endif |
|
198 endif |
4771
|
199 [as,bs,cs,ds] = sys2ss(mysys); |
3431
|
200 nt1 = n1 + nz1; |
|
201 if (!nt1) |
|
202 ## pure gain (pad B, C with zeros) |
|
203 B = [B, zeros(nt,m1)]; |
|
204 C = [C; zeros(p1,nt)]; |
|
205 else |
|
206 A = [A, zeros(nt,nt1); zeros(nt1,nt), as]; |
|
207 B = [B, zeros(nt,m1); zeros(nt1,m), bs]; |
|
208 C = [C, zeros(p,nt1); zeros(p1,nt), cs]; |
|
209 endif |
|
210 D = [D, zeros(p,m1); zeros(p1,m), ds]; |
|
211 n = n + n1; |
|
212 nz = nz + nz1; |
|
213 nt = nt + nt1; |
|
214 m = m + m1; |
|
215 p = p + p1; |
|
216 endfor |
|
217 |
|
218 ## check maximum dimensions |
|
219 [nx, mx] = size(Clst); |
|
220 if (nx > m) |
|
221 error("---> more rows in Clst than total number of inputs."); |
|
222 endif |
|
223 if (mx > p+1) |
|
224 error("---> more cols in Clst than total number of outputs."); |
|
225 endif |
|
226 ## empty vector Ulst is OK |
|
227 lul = length(Ulst); |
|
228 if (lul) |
4030
|
229 if (!isvector(Ulst)) |
3431
|
230 error("---> Input u list Ulst must be a vector."); |
|
231 endif |
|
232 if (lul > m) |
|
233 error("---> more values in Ulst than number of inputs."); |
|
234 endif |
|
235 endif |
|
236 if (!length(Olst)) Olst = [1:(p+lul)]; endif |
|
237 if (!length(Ilst)) Ilst = [1:m]; endif |
4030
|
238 if (!isvector(Olst)) |
3431
|
239 error("---> Output list Olst must be a vector."); |
|
240 endif |
4030
|
241 if (!isvector(Ilst)) |
3431
|
242 error("---> Input list Ilst must be a vector."); |
|
243 endif |
|
244 |
|
245 ## build the feedback "K" from the interconnection data Clst |
|
246 K = zeros(m, p); |
|
247 inp_used = zeros(m,1); |
|
248 for ii = 1:nx |
|
249 xx = Clst(ii,:); |
|
250 iu = xx(1); |
|
251 if ((iu < 1) || (iu > m)) |
|
252 error("---> invalid value in first col of Clst."); |
|
253 endif |
|
254 if (inp_used(iu)) |
|
255 error("---> Input specified more than once."); |
|
256 endif |
|
257 inp_used(iu) = 1; |
|
258 for kk = 2:mx |
|
259 it = xx(kk); |
|
260 if (abs(it) > p) |
|
261 error("---> invalid row value in Clst."); |
|
262 elseif (it) |
|
263 K(iu,abs(it)) = sign(it); |
|
264 endif |
|
265 endfor |
|
266 endfor |
|
267 |
|
268 ## form the "closed loop", i.e replace u in |
|
269 ## . |
|
270 ## x = Ax + Bu |
|
271 ## ~ |
|
272 ## y = Cx + Du by u = K*y+u |
|
273 ## |
|
274 ## -1 |
|
275 ## R = (I-D*K) must exist. |
|
276 |
|
277 R = eye(p) - D*K; |
|
278 if (rank(R) < p) |
|
279 error("---> singularity in algebraic loop."); |
|
280 else |
|
281 R = inv(R); |
|
282 endif |
|
283 A = A + B*K*R*C; |
|
284 B = B + B*K*R*D; |
|
285 C = R*C; |
|
286 D = R*D; |
|
287 |
|
288 ## append old inputs u to the outputs (if lul > 0) |
|
289 kc = K*C; |
|
290 kdi = eye(m) + K*D; |
|
291 for ii = 1:lul |
|
292 it = Ulst(ii); |
|
293 if ((it < 1) || (it > m)) |
|
294 error("---> invalid value in Ulst."); |
|
295 endif |
|
296 C = [C; kc(it,:)]; |
|
297 D = [D; kdi(it,:)]; |
|
298 endfor |
|
299 |
|
300 ## select and rearrange outputs |
|
301 nn = length(A); |
|
302 lol = length(Olst); |
|
303 Cnew = zeros(lol,nn); |
|
304 Dnew = zeros(lol,m); |
|
305 for ii = 1:lol |
|
306 iu = Olst(ii); |
|
307 if (!iu || (abs(iu) > p+lul)) |
|
308 error("---> invalid value in Olst."); |
|
309 endif |
|
310 Cnew(ii,:) = sign(iu)*C(abs(iu),:); |
|
311 Dnew(ii,:) = sign(iu)*D(abs(iu),:); |
|
312 endfor |
|
313 C = Cnew; |
|
314 D = Dnew; |
|
315 lil = length(Ilst); |
|
316 Bnew = zeros(nn,lil); |
|
317 Dnew = zeros(lol,lil); |
|
318 for ii = 1:lil |
|
319 iu = Ilst(ii); |
|
320 if (!iu || (abs(iu) > m)) |
|
321 error("---> invalid value in Ilst."); |
|
322 endif |
|
323 Bnew(:,ii) = sign(iu)*B(:,abs(iu)); |
|
324 Dnew(:,ii) = sign(iu)*D(:,abs(iu)); |
|
325 endfor |
|
326 |
4771
|
327 sys = ss(A, Bnew, C, Dnew, tsam, n, nz); |
3431
|
328 |
|
329 endfunction |