3430
|
1 ## Copyright (C) 1996 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 |
3439
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{retsys}, @var{nc}, @var{no}] =} sysmin (@var{sys}, @var{flg}) |
5016
|
21 ## Returns a minimal (or reduced order) system |
|
22 ## |
|
23 ## @strong{Inputs} |
|
24 ## @table @var |
|
25 ## @item sys |
|
26 ## System data structure |
|
27 ## @item flg |
|
28 ## When equal to 0 (default value), returns minimal system, |
|
29 ## in which state names are lost; when equal to 1, returns system |
|
30 ## with physical states removed that are either uncontrollable or |
|
31 ## unobservable (cannot reduce further without discarding physical |
|
32 ## meaning of states). |
|
33 ## @end table |
|
34 ## @strong{Outputs} |
|
35 ## @table @var |
|
36 ## @item retsys |
|
37 ## Returned system. |
|
38 ## @item nc |
|
39 ## Number of controllable states in the returned system. |
|
40 ## @item no |
|
41 ## Number of observable states in the returned system. |
|
42 ## @item cflg |
|
43 ## @code{is_controllable(retsys)}. |
|
44 ## @item oflg |
|
45 ## @code{is_observable(retsys)}. |
|
46 ## @end table |
3439
|
47 ## @end deftypefn |
3430
|
48 |
|
49 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
50 |
3439
|
51 function [retsys, nc, no, cflg, oflg] = sysmin (sys, flg) |
3430
|
52 |
|
53 switch(nargin) |
|
54 case(1), flg = 0; |
|
55 case(2), jnk = flg; # dummy operation |
|
56 otherwise, |
|
57 usage("[retsys,nc,no] = sysmin(sys{,flg})"); |
|
58 endswitch |
|
59 dflg = is_digital(sys,2); |
|
60 [n,nz,m,p] = sysdimensions(sys); |
|
61 if(n*nz > 0) |
|
62 # both continuous and discrete states |
|
63 [aa,bb,cc,dd,tsam,n,nz,stnam,innam,outnam,yd] = sys2ss(sys); |
|
64 crng = 1:n; |
|
65 drng = n+(1:nz); |
|
66 |
|
67 # get minimal realization of continuous part |
|
68 Ac = aa(crng,crng); |
|
69 Acd = aa(crng,drng); |
|
70 Adc = aa(drng,crng); |
|
71 Ad = aa(drng,drng); |
|
72 Bc = bb(crng,:); |
|
73 Bd = bb(drng,:); |
|
74 Cc = cc(:,crng); |
|
75 Cd = cc(:,drng); |
|
76 |
|
77 cstnam = stnam(crng); |
|
78 dstnam = stnam(drng); |
4771
|
79 cinnam = __sysconcat__(innam,stnam(drng)); |
|
80 coutnam = __sysconcat__(outnam,stnam(drng)); |
|
81 csys = ss(Ac,[Bc,Acd],[Cc;Adc]); |
3430
|
82 csys = syssetsignals(csys,"st",cstnam); |
|
83 csys = syssetsignals(csys,"in",cinnam); |
|
84 csys = syssetsignals(csys,"out",coutnam); |
|
85 |
|
86 # reduce continuous system, recombine with discrete part |
|
87 csys = sysmin(csys,flg); |
|
88 cn = sysdimensions(csys); |
|
89 |
|
90 if(cn == 0) |
|
91 # continuous states are removed; just reduce the discrete part |
|
92 sys = sysprune(sys,1:p,1:m,drng); |
|
93 retsys = sysmin(sys,flg); |
|
94 else |
|
95 # extract updated parameters from reduced continuous system |
|
96 [caa,cbb,ccc,cdd,ctsam,cn,cnz,cstnam,cinnam,coutnam] = sys2ss(csys); |
|
97 crng = 1:cn; |
|
98 Ac = caa; |
|
99 Bc = cbb(:,1:m); |
|
100 Acd = cbb(:,m+(1:nz)); |
|
101 Cc = ccc(1:p,:); |
|
102 Adc = ccc(p + (1:nz),:); |
|
103 |
|
104 # recombine to reduce discrete part of the system |
4771
|
105 dinnam = __sysconcat__(innam,cstnam); |
|
106 doutnam = __sysconcat__(outnam,cstnam); |
|
107 dsys = ss(Ad,[Bd,Adc],[Cd;Acd],[],tsam); |
3430
|
108 dsys = syssetsignals(dsys,"st",dstnam); |
|
109 dsys = syssetsignals(dsys,"in",dinnam); |
|
110 dsys = syssetsignals(dsys,"out",doutnam); |
|
111 |
|
112 # reduce discrete subsystem |
|
113 dsys = sysmin(dsys); |
|
114 [n1,nz] = sysdimensions(dsys); |
|
115 if(nz == 0) |
|
116 # discrete subsystem is not needed |
|
117 retsys = sysprune(csys,1:p,1:m); |
|
118 else |
|
119 # combine discrete, continuous subsystems |
|
120 [Ad,dbb,dcc] = sys2ss(dsys); |
|
121 dstnam = sysgetsignals(dsys,"st"); |
|
122 Bd = dbb(:,1:m); |
|
123 Adc = dbb(:,m+(1:cn)); |
|
124 Cd = dcc(1:p,:); |
|
125 Acd = dcc(p+(1:cn),:); |
4771
|
126 stnam = __sysconcat__(cstnam,dstnam); |
3430
|
127 aa = [Ac, Acd; Adc, Ad]; |
|
128 bb = [Bc; Bd]; |
|
129 cc = [Cc, Cd]; |
4771
|
130 retsys = ss([Ac, Acd; Adc, Ad], [Bc ; Bd], [Cc, Cd], dd, tsam, ... |
3430
|
131 cn, nz, stnam, innam, outnam, find(yd == 1)); |
|
132 end |
|
133 endif |
|
134 else |
|
135 Ts = sysgettsam(sys); |
|
136 switch(flg) |
|
137 case(0), |
|
138 ## reduce to a minimal system |
|
139 [aa,bb,cc,dd] = sys2ss(sys); |
|
140 [cflg,Uc] = is_controllable(aa,bb); |
|
141 if(!cflg) |
|
142 ## reduce to controllable states |
|
143 if(!isempty(Uc)) |
|
144 aa = Uc'*aa*Uc; |
|
145 bb = Uc'*bb; |
|
146 cc = cc*Uc; |
|
147 else |
|
148 aa = bb = cc = []; |
|
149 endif |
|
150 endif |
|
151 if(!isempty(aa)) |
|
152 [oflg,Uo] = is_observable(aa,cc); |
|
153 if(!oflg) |
|
154 if(!isempty(Uo)) |
|
155 aa = Uo'*aa*Uo; |
|
156 bb = Uo'*bb; |
|
157 cc = cc*Uo; |
|
158 else |
|
159 aa = bb = cc = []; |
|
160 endif |
|
161 endif |
|
162 endif |
|
163 switch(dflg) |
|
164 case(0), |
|
165 nc = no = nn = columns(aa); |
|
166 nz = 0; |
|
167 case(1), |
|
168 nc = no = nz = columns(aa); |
|
169 nn = 0; |
|
170 endswitch |
|
171 innam = sysgetsignals(sys,"in"); |
|
172 outnam= sysgetsignals(sys,"out"); |
4771
|
173 retsys = ss(aa,bb,cc,dd,Ts,nn,nz,[],innam,outnam); |
3430
|
174 case(1), |
|
175 ## reduced model with physical states |
|
176 [cflg,Uc] = is_controllable(sys); xc = find(max(abs(Uc')) != 0); |
|
177 [oflg,Uo] = is_observable(sys); xo = find(max(abs(Uo')) != 0); |
|
178 xx = intersection(xc,xo); |
|
179 if(isempty(xx)) xx = 0; endif # signal no states in reduced model |
|
180 retsys = sysprune(sys,[],[],xx); |
|
181 otherwise, |
|
182 error ("invalid value of flg = %d", flg); |
|
183 endswitch |
|
184 if(sysdimensions(retsys,"st") > 0) |
|
185 [cflg,Uc] = is_controllable(retsys); nc = columns(Uc); |
|
186 [oflg,Uo] = is_observable(retsys); no = columns(Uo); |
|
187 else |
|
188 nc = no = 0; |
|
189 endif |
|
190 endif |
|
191 endfunction |