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