3381
|
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. |
3346
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File } { @var{sys} =} sysgroup ( @var{Asys}, @var{Bsys}) |
|
21 ## Combines two systems into a single system |
|
22 ## |
|
23 ## @strong{Inputs} |
|
24 ## @var{Asys}, @var{Bsys}: system data structures |
|
25 ## |
|
26 ## @strong{Outputs} |
|
27 ## @math{sys = @r{block diag}(Asys,Bsys)} |
|
28 ## @example |
|
29 ## @group |
|
30 ## __________________ |
|
31 ## | ________ | |
|
32 ## u1 ----->|--> | Asys |--->|----> y1 |
|
33 ## | -------- | |
|
34 ## | ________ | |
|
35 ## u2 ----->|--> | Bsys |--->|----> y2 |
|
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 ## |
|
47 ## @end deftypefn |
3213
|
48 |
3279
|
49 function sys = sysgroup(...) |
3381
|
50 |
|
51 ## A. S. Hodel August 1995 |
|
52 ## modified by John Ingram July 1996 |
|
53 ## A. S. Hodel: modified for variable number of arguments 1999 |
3213
|
54 |
|
55 save_val = implicit_str_to_num_ok; # save for later |
|
56 implicit_str_to_num_ok = 1; |
|
57 |
|
58 save_emp = empty_list_elements_ok; |
|
59 empty_list_elements_ok = 1; |
|
60 |
3279
|
61 |
|
62 if(nargin < 1) |
|
63 usage("sys = sysgroup(Asys{,Bsys,...})"); |
3213
|
64 endif |
|
65 |
3381
|
66 ## collect all arguments |
3279
|
67 arglist = list(); |
|
68 va_start(); |
|
69 for kk=1:nargin |
|
70 arglist(kk) = va_arg(); |
|
71 if(!is_struct(nth(arglist,kk))) |
|
72 error("sysgroup: argument %d is not a data structure",kk); |
|
73 endif |
|
74 endfor |
3213
|
75 |
3279
|
76 if(nargin == 2) |
3381
|
77 ## the usual case; group the two systems together |
3279
|
78 Asys = nth(arglist,1); |
|
79 Bsys = nth(arglist,2); |
|
80 |
3381
|
81 ## extract information from Asys, Bsys to consruct sys |
3279
|
82 Asys = sysupdate(Asys,"ss"); |
|
83 Bsys = sysupdate(Bsys,"ss"); |
|
84 [n1,nz1,m1,p1] = sysdimensions(Asys); |
|
85 [n2,nz2,m2,p2] = sysdimensions(Bsys); |
|
86 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys); |
|
87 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys); |
|
88 nA = An + Anz; |
|
89 nB = Bn + Bnz; |
|
90 |
|
91 if(p1*m1*p2*m2 == 0) |
|
92 error("sysgroup: argument lacks inputs and/or outputs"); |
|
93 |
|
94 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
|
95 warning("sysgroup: creating combination of continuous and discrete systems") |
|
96 |
|
97 elseif(Atsam != Btsam) |
|
98 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
|
99 endif |
|
100 |
|
101 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba]; |
|
102 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb]; |
|
103 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc]; |
|
104 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd]; |
|
105 tsam = max(Atsam,Btsam); |
|
106 |
3381
|
107 ## construct combined signal names; stnames must check for pure gain blocks |
3279
|
108 if(isempty(Ast)) |
|
109 stname = Bst; |
|
110 elseif(isempty(Bst)) |
|
111 stname = Ast; |
|
112 else |
|
113 stname = append(Ast, Bst); |
|
114 endif |
|
115 inname = append(Ain, Bin); |
|
116 outname = append(Aout,Bout); |
|
117 |
3381
|
118 ## Sort states into continous first, then discrete |
3279
|
119 dstates = ones(1,(nA+nB)); |
|
120 if(An) |
|
121 dstates(1:(An)) = zeros(1,An); |
|
122 endif |
|
123 if(Bn) |
|
124 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
|
125 endif |
|
126 [tmp,pv] = sort(dstates); |
|
127 A = A(pv,pv); |
|
128 B = B(pv,:); |
|
129 C = C(:,pv); |
|
130 stname = stname(pv); |
|
131 |
3381
|
132 ## check for duplicate signal names |
3279
|
133 inname = sysgroupn(inname,"input"); |
|
134 stname = sysgroupn(stname,"state"); |
|
135 outname = sysgroupn(outname,"output"); |
|
136 |
3381
|
137 ## mark discrete outputs |
3279
|
138 outlist = find([Ayd, Byd]); |
|
139 |
3381
|
140 ## build new system |
3279
|
141 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
|
142 |
|
143 else |
3381
|
144 ## multiple systems (or a single system); combine together one by one |
3279
|
145 sys = nth(arglist,1); |
|
146 for kk=2:length(arglist) |
|
147 printf("sysgroup: kk=%d\n",kk); |
|
148 sys = sysgroup(sys,nth(arglist,kk)); |
|
149 endfor |
3213
|
150 endif |
3279
|
151 |
3213
|
152 implicit_str_to_num_ok = save_val; # restore value |
|
153 empty_list_elements_ok = save_emp; |
3279
|
154 |
3213
|
155 endfunction |