3279
|
1 # Copyright (C) 1996 Auburn University. All Rights Reserved. |
3213
|
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. |
3213
|
18 |
|
19 function [dsys,Adc,Cdc] = sysdisc(sys) |
|
20 # function [dsys,Adc,Cdc] = sysdisc(sys) |
|
21 # inputs: sys = system data structure |
|
22 # outputs: |
|
23 # dsys: purely discrete portion of sys (returned empty if there is |
|
24 # no purely discrete path from inputs to outputs) |
|
25 # Adc, Cdc: connections from continuous states to discrete states/discrete |
|
26 # outputs, respectively. |
|
27 # |
|
28 |
|
29 save_val = implicit_str_to_num_ok; # save for later |
|
30 save_empty = empty_list_elements_ok; |
|
31 empty_list_elements_ok = implicit_str_to_num_ok = 1; |
|
32 |
|
33 |
|
34 if (nargin != 1) |
|
35 usage("[dsys,Adc,Cdc] = sysdisc(sys)"); |
|
36 elseif (!is_struct(sys)) |
|
37 error("sys must be in system data structure form"); |
|
38 endif |
|
39 |
|
40 sys = sysupdate(sys,"ss"); |
|
41 [n_tot,st_c,st_d,y_c,y_d] = syscont_disc(sys); # get ranges |
|
42 |
|
43 # assume there's nothing there; build partitions as appropriate |
|
44 Add = Adc = Bdd = Cdd = Cdc = Ddd = []; |
|
45 |
|
46 if(isempty(st_d) & isempty(y_d)) |
|
47 error("sysdisc: expecting discrete states and/or continous outputs"); |
|
48 elseif (isempty(st_d)) |
|
49 warning("sysdisc: no discrete states"); |
|
50 elseif(isempty(y_d)) |
|
51 warning("sysdisc: no discrete outputs"); |
|
52 endif |
|
53 |
3228
|
54 [aa,bb,cc,dd] = sys2ss(sys); |
3213
|
55 if(!isempty(st_d) ) |
3228
|
56 Add = aa( st_d , st_d); |
|
57 stname = sysgetsignals(sys,"st",st_d); |
|
58 Bdd = bb( st_d , :); |
3213
|
59 if(!isempty(st_c)) |
3228
|
60 Adc = aa( st_d , st_c); |
3213
|
61 endif |
|
62 if(!isempty(y_d)) |
3228
|
63 Cdd = cc(y_d , st_d); |
3213
|
64 endif |
|
65 else |
|
66 stname = []; |
|
67 endif |
|
68 if(!isempty(y_d)) |
3228
|
69 Ddd = dd(y_d , :); |
|
70 outname = sysgetsignals(sys,"out",y_d); |
3213
|
71 if(!isempty(st_c)) |
3228
|
72 Cdc = cc(y_d , st_c); |
3213
|
73 endif |
|
74 else |
|
75 outname=[]; |
|
76 endif |
3228
|
77 inname = sysgetsignals(sys,"in"); |
3213
|
78 outlist = 1:rows(outname); |
|
79 |
|
80 if(!isempty(outname)) |
3228
|
81 tsam = sysgettsam(sys); |
|
82 [nc,nz] = sysdimensions(sys); |
|
83 dsys = ss2sys(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist); |
3213
|
84 else |
|
85 dsys=[]; |
|
86 endif |
|
87 implicit_str_to_num_ok = save_val; # restore value |
|
88 empty_list_elements_ok = save_empty; |
|
89 |
|
90 endfunction |