3381
|
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 ## Written by A. S. Hodel a.s.hodel@eng.auburn.edu |
3279
|
20 |
3385
|
21 function [retsys, nc, no, cflg, oflg] = sysmin (sys, flg); |
3381
|
22 |
|
23 ## [retsys,nc,no] = sysmin(sys{,flg}); |
|
24 ## return a minimal (or reduced order) system |
|
25 ## inputs: |
|
26 ## sys: system data structure |
|
27 ## flg: 0 [default] return minimal system; state names lost |
|
28 ## : 1 return system with physical states removed that |
|
29 ## are either uncontrollable or unobservable |
|
30 ## (cannot reduce further without discarding physical |
|
31 ## meaning of states) |
|
32 ## outputs: |
|
33 ## retsys: returned system |
|
34 ## nc: number of controllable states in the returned system |
|
35 ## no: number of observable states in the returned system |
|
36 ## cflg: is_controllable(retsys) |
|
37 ## oflg: is_observable(retsys) |
3276
|
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,flg); |
|
46 Ts = sysgettsam(sys); |
|
47 switch(flg) |
|
48 case(0), |
3381
|
49 ## reduce to a minimal system |
3276
|
50 [aa,bb,cc,dd] = sys2ss(sys); |
|
51 [cflg,Uc] = is_controllable(aa,bb); |
|
52 if(!cflg) |
3381
|
53 ## reduce to controllable states |
3276
|
54 if(!isempty(Uc)) |
|
55 aa = Uc'*aa*Uc; |
|
56 bb = Uc'*bb; |
|
57 cc = cc*Uc; |
|
58 else |
|
59 aa = bb = cc = []; |
|
60 endif |
|
61 endif |
|
62 if(!isempty(aa)) |
|
63 [oflg,Uo] = is_observable(aa,cc); |
|
64 if(!oflg) |
|
65 if(!isempty(Uo)) |
|
66 aa = Uo'*aa*Uo; |
|
67 bb = Uo'*bb; |
|
68 cc = cc*Uo; |
|
69 else |
|
70 aa = bb = cc = []; |
|
71 endif |
|
72 endif |
|
73 endif |
|
74 switch(dflg) |
|
75 case(0), |
|
76 nc = no = nn = columns(aa); |
|
77 nz = 0; |
|
78 case(1), |
|
79 nc = no = nz = columns(aa); |
|
80 nn = 0; |
|
81 endswitch |
|
82 inname = sysgetsignals(sys,"in"); |
|
83 outname= sysgetsignals(sys,"out"); |
|
84 retsys = ss2sys(aa,bb,cc,dd,Ts,nn,nz,[],inname,outname); |
|
85 case(1), |
3381
|
86 ## reduced model with physical states |
3276
|
87 [cflg,Uc] = is_controllable(sys); xc = find(max(abs(Uc')) != 0); |
|
88 [oflg,Uo] = is_observable(sys); xo = find(max(abs(Uo')) != 0); |
|
89 xx = intersection(xc,xo); |
|
90 if(isempty(xx)) xx = 0; endif # signal no states in reduced model |
|
91 retsys = sysprune(sys,[],[],xx); |
|
92 otherwise, |
|
93 error("illegal value of flg=%d",flg); |
|
94 endswitch |
|
95 if(sysdimensions(retsys,"st") > 0) |
|
96 [cflg,Uc] = is_controllable(retsys); nc = columns(Uc); |
|
97 [oflg,Uo] = is_observable(retsys); no = columns(Uo); |
|
98 else |
|
99 nc = no = 0; |
|
100 endif |
|
101 endfunction |