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