3213
|
1 # Copyright (C) 1996,1998 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
|
19 function sys = sysgroup(Asys,Bsys) |
|
20 # function sys = sysgroup(Asys,Bsys) |
|
21 # Combines two system data structures into a single system |
|
22 # |
|
23 # input: Asys, Bsys: system data structures |
|
24 # output: sys: Asys and Bsys are combined into a single system: |
|
25 # |
|
26 # __________________ |
|
27 # | ________ | |
|
28 # u1 ----->|--> | Asys |--->|----> y1 |
|
29 # | -------- | |
|
30 # | ________ | |
|
31 # u2 ----->|--> | Bsys |--->|----> y2 |
|
32 # | -------- | |
|
33 # ------------------ |
|
34 # Ksys |
|
35 # |
|
36 # The function also rearranges the A,B,C matrices so that the |
|
37 # continuous states come first and the discrete states come last. |
|
38 # If there are duplicate names, the second name has a unique suffix appended |
|
39 # on to the end of the name. |
|
40 |
|
41 # A. S. Hodel August 1995 |
|
42 # modified by John Ingram July 1996 |
|
43 |
|
44 save_val = implicit_str_to_num_ok; # save for later |
|
45 implicit_str_to_num_ok = 1; |
|
46 |
|
47 save_emp = empty_list_elements_ok; |
|
48 empty_list_elements_ok = 1; |
|
49 |
|
50 if(nargin ~= 2) |
|
51 usage("sys = sysgroup(Asys,Bsys)"); |
|
52 elseif( !is_struct(Asys) | !is_struct(Bsys) ) |
|
53 error("sysgroup: input arguments must both be structured systems"); |
|
54 endif |
|
55 |
|
56 # extract information from Asys, Bsys to consruct sys |
|
57 Asys = sysupdate(Asys,"ss"); |
|
58 Bsys = sysupdate(Bsys,"ss"); |
|
59 [n1,nz1,m1,p1] = sysdimensions(Asys); |
|
60 [n2,nz2,m2,p2] = sysdimensions(Bsys); |
|
61 [Aa,Ab,Ac,Ad,Atsam,An,Anz,Ast,Ain,Aout,Ayd] = sys2ss(Asys); |
|
62 [Ba,Bb,Bc,Bd,Btsam,Bn,Bnz,Bst,Bin,Bout,Byd] = sys2ss(Bsys); |
|
63 nA = An + Anz; |
|
64 nB = Bn + Bnz; |
|
65 |
|
66 if(p1*m1*p2*m2 == 0) |
|
67 error("sysgroup: argument lacks inputs and/or outputs"); |
|
68 |
|
69 elseif((Atsam + Btsam > 0) & (Atsam * Btsam == 0) ) |
|
70 warning("sysgroup: creating combination of continuous and discrete systems") |
|
71 |
|
72 elseif(Atsam != Btsam) |
3228
|
73 error("sysgroup: Asys.tsam=%e, Bsys.tsam =%e", Atsam, Btsam); |
3213
|
74 endif |
|
75 |
|
76 A = [Aa,zeros(nA,nB); zeros(nB,nA),Ba]; |
|
77 B = [Ab,zeros(nA,m2); zeros(nB,m1),Bb]; |
|
78 C = [Ac,zeros(p1,nB); zeros(p2,nA),Bc]; |
|
79 D = [Ad,zeros(p1,m2); zeros(p2,m1),Bd]; |
|
80 tsam = max(Atsam,Btsam); |
|
81 |
|
82 # construct combined signal names; stnames must check for pure gain blocks |
|
83 if(isempty(Ast)) |
|
84 stname = Bst; |
|
85 elseif(isempty(Bst)) |
|
86 stname = Ast; |
|
87 else |
3228
|
88 stname = append(Ast, Bst); |
3213
|
89 endif |
3228
|
90 inname = append(Ain, Bin); |
|
91 outname = append(Aout,Bout); |
3213
|
92 |
|
93 # Sort states into continous first, then discrete |
|
94 dstates = ones(1,(nA+nB)); |
|
95 if(An) |
|
96 dstates(1:(An)) = zeros(1,An); |
|
97 endif |
|
98 if(Bn) |
|
99 dstates((nA+1):(nA+Bn)) = zeros(1,Bn); |
|
100 endif |
|
101 [tmp,pv] = sort(dstates); |
|
102 A = A(pv,pv); |
|
103 B = B(pv,:); |
|
104 C = C(:,pv); |
3228
|
105 stname = stname(pv); |
3213
|
106 |
|
107 # check for duplicate signal names |
|
108 inname = sysgroupn(inname,"input"); |
|
109 stname = sysgroupn(stname,"state"); |
|
110 outname = sysgroupn(outname,"output"); |
|
111 |
|
112 # mark discrete outputs |
|
113 outlist = find([Ayd, Byd]); |
|
114 |
|
115 # build new system |
|
116 sys = ss2sys(A,B,C,D,tsam,An+Bn,Anz+Bnz,stname,inname,outname); |
|
117 |
|
118 implicit_str_to_num_ok = save_val; # restore value |
|
119 empty_list_elements_ok = save_emp; |
|
120 |
|
121 endfunction |