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