3213
|
1 # Copyright (C) 1996 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
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 # $Revision: 1.1.1.1 $ |
|
30 |
|
31 save_val = implicit_str_to_num_ok; # save for later |
|
32 save_empty = empty_list_elements_ok; |
|
33 empty_list_elements_ok = implicit_str_to_num_ok = 1; |
|
34 |
|
35 |
|
36 if (nargin != 1) |
|
37 usage("[dsys,Adc,Cdc] = sysdisc(sys)"); |
|
38 elseif (!is_struct(sys)) |
|
39 error("sys must be in system data structure form"); |
|
40 endif |
|
41 |
|
42 sys = sysupdate(sys,"ss"); |
|
43 [n_tot,st_c,st_d,y_c,y_d] = syscont_disc(sys); # get ranges |
|
44 |
|
45 # assume there's nothing there; build partitions as appropriate |
|
46 Add = Adc = Bdd = Cdd = Cdc = Ddd = []; |
|
47 |
|
48 if(isempty(st_d) & isempty(y_d)) |
|
49 error("sysdisc: expecting discrete states and/or continous outputs"); |
|
50 elseif (isempty(st_d)) |
|
51 warning("sysdisc: no discrete states"); |
|
52 elseif(isempty(y_d)) |
|
53 warning("sysdisc: no discrete outputs"); |
|
54 endif |
|
55 |
|
56 if(!isempty(st_d) ) |
|
57 Add = sys.a( st_d , st_d); |
|
58 stname = sys.stname(st_d , :); |
|
59 Bdd = sys.b( st_d , :); |
|
60 if(!isempty(st_c)) |
|
61 Adc = sys.a( st_d , st_c); |
|
62 endif |
|
63 if(!isempty(y_d)) |
|
64 Cdd = sys.c(y_d , st_d); |
|
65 endif |
|
66 else |
|
67 stname = []; |
|
68 endif |
|
69 if(!isempty(y_d)) |
|
70 Ddd = sys.d(y_d , :); |
|
71 outname = sys.outname(y_d , :); |
|
72 if(!isempty(st_c)) |
|
73 Cdc = sys.c(y_d , st_c); |
|
74 endif |
|
75 else |
|
76 outname=[]; |
|
77 endif |
|
78 inname = sys.inname; |
|
79 outlist = 1:rows(outname); |
|
80 |
|
81 if(!isempty(outname)) |
|
82 dsys = ss2sys(Add,Bdd,Cdd,Ddd,sys.tsam,0,sys.nz,stname, ... |
|
83 inname,outname,outlist); |
|
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 |