3279
|
1 # Copyright (C) 1996, 1998, 1999 Auburn University. All Rights Reserved. |
3213
|
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 |
3284
|
17 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
3213
|
18 |
3279
|
19 function sys = sysgroup(...) |
|
20 # function sys = sysgroup(Asys{,Bsys,...}) |
|
21 # Parallel connection of systems |
3213
|
22 # |
3279
|
23 # inputs: All input arguments must be system data structures; |
|
24 # exits with an error if there is not at least one argument |
|
25 # output: sys: all systems are combined into a single system; e.g., |
|
26 # if two systems are passed as sysgroup(Asys,Bsys), the result |
|
27 # is |
3213
|
28 # |
|
29 # __________________ |
|
30 # | ________ | |
|
31 # u1 ----->|--> | Asys |--->|----> y1 |
|
32 # | -------- | |
|
33 # | ________ | |
|
34 # u2 ----->|--> | Bsys |--->|----> y2 |
|
35 # | -------- | |
|
36 # ------------------ |
|
37 # Ksys |
|
38 # |
|
39 # The function also rearranges the A,B,C matrices so that the |
|
40 # continuous states come first and the discrete states come last. |
|
41 # If there are duplicate names, the second name has a unique suffix appended |
3279
|
42 # on to the end of the name (a warning message is printed). |
3213
|
43 |
|
44 # A. S. Hodel August 1995 |
|
45 # modified by John Ingram July 1996 |
3279
|
46 # A. S. Hodel: modified for variable number of arguments 1999 |
3213
|
47 |
|
48 save_val = implicit_str_to_num_ok; # save for later |
|
49 implicit_str_to_num_ok = 1; |
|
50 |
|
51 save_emp = empty_list_elements_ok; |
|
52 empty_list_elements_ok = 1; |
|
53 |
3279
|
54 |
|
55 if(nargin < 1) |
|
56 usage("sys = sysgroup(Asys{,Bsys,...})"); |
3213
|
57 endif |
|
58 |
3279
|
59 # collect all arguments |
|
60 arglist = list(); |
|
61 va_start(); |
|
62 for kk=1:nargin |
|
63 arglist(kk) = va_arg(); |
|
64 if(!is_struct(nth(arglist,kk))) |
|
65 error("sysgroup: argument %d is not a data structure",kk); |
|
66 endif |
|
67 endfor |
3213
|
68 |
3279
|
69 if(nargin == 2) |
|
70 # the usual case; group the two systems together |
|
71 Asys = nth(arglist,1); |
|
72 Bsys = nth(arglist,2); |
|
73 |
|
74 # extract information from Asys, Bsys to consruct sys |
|
75 Asys = sysupdate(Asys,"ss"); |
|
76 Bsys = sysupdate(Bsys,"ss"); |
|
77 [n1,nz1,m1,p1] = sysdimensions(Asys); |
|
78 [n2,nz2,m2,p2] = sysdimensions(Bsys); |
|
79 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys); |
|
80 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys); |
|
81 nA = An + Anz; |
|
82 nB = Bn + Bnz; |
|
83 |
|
84 if(p1*m1*p2*m2 == 0) |
|
85 error("sysgroup: argument lacks inputs and/or outputs"); |
|
86 |
|
87 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
|
88 warning("sysgroup: creating combination of continuous and discrete systems") |
|
89 |
|
90 elseif(Atsam != Btsam) |
|
91 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
|
92 endif |
|
93 |
|
94 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba]; |
|
95 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb]; |
|
96 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc]; |
|
97 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd]; |
|
98 tsam = max(Atsam,Btsam); |
|
99 |
|
100 # construct combined signal names; stnames must check for pure gain blocks |
|
101 if(isempty(Ast)) |
|
102 stname = Bst; |
|
103 elseif(isempty(Bst)) |
|
104 stname = Ast; |
|
105 else |
|
106 stname = append(Ast, Bst); |
|
107 endif |
|
108 inname = append(Ain, Bin); |
|
109 outname = append(Aout,Bout); |
|
110 |
|
111 # Sort states into continous first, then discrete |
|
112 dstates = ones(1,(nA+nB)); |
|
113 if(An) |
|
114 dstates(1:(An)) = zeros(1,An); |
|
115 endif |
|
116 if(Bn) |
|
117 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
|
118 endif |
|
119 [tmp,pv] = sort(dstates); |
|
120 A = A(pv,pv); |
|
121 B = B(pv,:); |
|
122 C = C(:,pv); |
|
123 stname = stname(pv); |
|
124 |
|
125 # check for duplicate signal names |
|
126 inname = sysgroupn(inname,"input"); |
|
127 stname = sysgroupn(stname,"state"); |
|
128 outname = sysgroupn(outname,"output"); |
|
129 |
|
130 # mark discrete outputs |
|
131 outlist = find([Ayd, Byd]); |
|
132 |
|
133 # build new system |
|
134 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
|
135 |
|
136 else |
|
137 # multiple systems (or a single system); combine together one by one |
|
138 sys = nth(arglist,1); |
|
139 for kk=2:length(arglist) |
|
140 printf("sysgroup: kk=%d\n",kk); |
|
141 sys = sysgroup(sys,nth(arglist,kk)); |
|
142 endfor |
3213
|
143 endif |
3279
|
144 |
3213
|
145 implicit_str_to_num_ok = save_val; # restore value |
|
146 empty_list_elements_ok = save_emp; |
3279
|
147 |
3213
|
148 endfunction |