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