Mercurial > hg > octave-lyh
comparison scripts/control/system/sysgroup.m @ 4771:b8105302cfe8
[project @ 2004-02-16 17:45:50 by jwe]
author | jwe |
---|---|
date | Mon, 16 Feb 2004 17:45:50 +0000 |
parents | cef48c4b902d |
children | bdbee5282954 |
comparison
equal
deleted
inserted
replaced
4770:ef5e598f099b | 4771:b8105302cfe8 |
---|---|
59 if(nargin < 1) | 59 if(nargin < 1) |
60 usage("sys = sysgroup(Asys{,Bsys,...})"); | 60 usage("sys = sysgroup(Asys{,Bsys,...})"); |
61 endif | 61 endif |
62 | 62 |
63 ## collect all arguments | 63 ## collect all arguments |
64 arglist = list(); | 64 arglist = {}; |
65 for kk=1:nargin | 65 for kk=1:nargin |
66 arglist(kk) = varargin{kk}; | 66 arglist(kk) = varargin{kk}; |
67 if(!isstruct(nth(arglist,kk))) | 67 if(!isstruct(arglist{kk})) |
68 error("sysgroup: argument %d is not a data structure",kk); | 68 error("sysgroup: argument %d is not a data structure",kk); |
69 endif | 69 endif |
70 endfor | 70 endfor |
71 | 71 |
72 if(nargin == 2) | 72 if(nargin == 2) |
73 ## the usual case; group the two systems together | 73 ## the usual case; group the two systems together |
74 Asys = nth(arglist,1); | 74 Asys = arglist{1}; |
75 Bsys = nth(arglist,2); | 75 Bsys = arglist{2}; |
76 | 76 |
77 ## extract information from Asys, Bsys to consruct sys | 77 ## extract information from Asys, Bsys to consruct sys |
78 Asys = sysupdate(Asys,"ss"); | 78 Asys = sysupdate(Asys,"ss"); |
79 Bsys = sysupdate(Bsys,"ss"); | 79 Bsys = sysupdate(Bsys,"ss"); |
80 [n1,nz1,m1,p1] = sysdimensions(Asys); | 80 [n1,nz1,m1,p1] = sysdimensions(Asys); |
92 | 92 |
93 elseif(Atsam != Btsam) | 93 elseif(Atsam != Btsam) |
94 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); | 94 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
95 endif | 95 endif |
96 | 96 |
97 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba]; | 97 if(nA*nB > 0) |
98 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb]; | 98 A12 = zeros(nA,nB); |
99 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc]; | 99 else |
100 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd]; | 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]; | |
101 tsam = max(Atsam,Btsam); | 145 tsam = max(Atsam,Btsam); |
102 | 146 |
103 ## construct combined signal names; stnames must check for pure gain blocks | 147 ## construct combined signal names; stnames must check for pure gain blocks |
104 if(isempty(Ast)) | 148 if(isempty(Ast)) |
105 stname = Bst; | 149 stname = Bst; |
106 elseif(isempty(Bst)) | 150 elseif(isempty(Bst)) |
107 stname = Ast; | 151 stname = Ast; |
108 else | 152 else |
109 stname = append(Ast, Bst); | 153 stname= __sysconcat__(Ast,Bst); |
110 endif | 154 endif |
111 inname = append(Ain, Bin); | 155 inname = __sysconcat__(Ain,Bin); |
112 outname = append(Aout,Bout); | 156 outname = __sysconcat__(Aout,Bout); |
113 | 157 |
114 ## Sort states into continous first, then discrete | 158 ## Sort states into continous first, then discrete |
115 dstates = ones(1,(nA+nB)); | 159 dstates = ones(1,(nA+nB)); |
116 if(An) | 160 if(An) |
117 dstates(1:(An)) = zeros(1,An); | 161 dstates(1:(An)) = zeros(1,An); |
132 | 176 |
133 ## mark discrete outputs | 177 ## mark discrete outputs |
134 outlist = find([Ayd, Byd]); | 178 outlist = find([Ayd, Byd]); |
135 | 179 |
136 ## build new system | 180 ## build new system |
137 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); | 181 sys = ss(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
138 | 182 |
139 else | 183 else |
140 ## multiple systems (or a single system); combine together one by one | 184 ## multiple systems (or a single system); combine together one by one |
141 sys = nth(arglist,1); | 185 sys = arglist{1}; |
142 for kk=2:length(arglist) | 186 for kk=2:length(arglist) |
143 printf("sysgroup: kk=%d\n",kk); | 187 printf("sysgroup: kk=%d\n",kk); |
144 sys = sysgroup(sys,nth(arglist,kk)); | 188 sys = sysgroup(sys,arglist{kk}); |
145 endfor | 189 endfor |
146 endif | 190 endif |
147 | 191 |
148 unwind_protect_cleanup | 192 unwind_protect_cleanup |
149 warn_empty_list_elements = save_warn_empty_list_elements; | 193 warn_empty_list_elements = save_warn_empty_list_elements; |