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 |
|
55 save_emp = empty_list_elements_ok; |
|
56 empty_list_elements_ok = 1; |
|
57 |
|
58 if(nargin < 1) |
|
59 usage("sys = sysgroup(Asys{,Bsys,...})"); |
|
60 endif |
|
61 |
|
62 ## collect all arguments |
|
63 arglist = list(); |
|
64 for kk=1:nargin |
3979
|
65 arglist(kk) = varargin{kk}; |
3430
|
66 if(!is_struct(nth(arglist,kk))) |
|
67 error("sysgroup: argument %d is not a data structure",kk); |
|
68 endif |
|
69 endfor |
|
70 |
|
71 if(nargin == 2) |
|
72 ## the usual case; group the two systems together |
|
73 Asys = nth(arglist,1); |
|
74 Bsys = nth(arglist,2); |
|
75 |
|
76 ## extract information from Asys, Bsys to consruct sys |
|
77 Asys = sysupdate(Asys,"ss"); |
|
78 Bsys = sysupdate(Bsys,"ss"); |
|
79 [n1,nz1,m1,p1] = sysdimensions(Asys); |
|
80 [n2,nz2,m2,p2] = sysdimensions(Bsys); |
|
81 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys); |
|
82 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys); |
|
83 nA = An + Anz; |
|
84 nB = Bn + Bnz; |
|
85 |
|
86 if(p1*m1*p2*m2 == 0) |
|
87 error("sysgroup: argument lacks inputs and/or outputs"); |
|
88 |
|
89 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
|
90 warning("sysgroup: creating combination of continuous and discrete systems") |
|
91 |
|
92 elseif(Atsam != Btsam) |
|
93 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
|
94 endif |
|
95 |
|
96 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba]; |
|
97 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb]; |
|
98 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc]; |
|
99 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd]; |
|
100 tsam = max(Atsam,Btsam); |
|
101 |
|
102 ## construct combined signal names; stnames must check for pure gain blocks |
|
103 if(isempty(Ast)) |
|
104 stname = Bst; |
|
105 elseif(isempty(Bst)) |
|
106 stname = Ast; |
|
107 else |
|
108 stname = append(Ast, Bst); |
|
109 endif |
|
110 inname = append(Ain, Bin); |
|
111 outname = append(Aout,Bout); |
|
112 |
|
113 ## Sort states into continous first, then discrete |
|
114 dstates = ones(1,(nA+nB)); |
|
115 if(An) |
|
116 dstates(1:(An)) = zeros(1,An); |
|
117 endif |
|
118 if(Bn) |
|
119 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
|
120 endif |
|
121 [tmp,pv] = sort(dstates); |
|
122 A = A(pv,pv); |
|
123 B = B(pv,:); |
|
124 C = C(:,pv); |
|
125 stname = stname(pv); |
|
126 |
|
127 ## check for duplicate signal names |
3438
|
128 inname = __sysgroupn__ (inname, "input"); |
|
129 stname = __sysgroupn__ (stname, "state"); |
|
130 outname = __sysgroupn__ (outname, "output"); |
3430
|
131 |
|
132 ## mark discrete outputs |
|
133 outlist = find([Ayd, Byd]); |
|
134 |
|
135 ## build new system |
|
136 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
|
137 |
|
138 else |
|
139 ## multiple systems (or a single system); combine together one by one |
|
140 sys = nth(arglist,1); |
|
141 for kk=2:length(arglist) |
|
142 printf("sysgroup: kk=%d\n",kk); |
|
143 sys = sysgroup(sys,nth(arglist,kk)); |
|
144 endfor |
|
145 endif |
|
146 |
|
147 empty_list_elements_ok = save_emp; |
|
148 |
|
149 endfunction |