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