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