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_empty = empty_list_elements_ok; |
3383
|
49 empty_list_elements_ok = 1; |
3213
|
50 |
|
51 |
|
52 if (nargin != 1) |
|
53 usage("[dsys,Adc,Cdc] = sysdisc(sys)"); |
|
54 elseif (!is_struct(sys)) |
|
55 error("sys must be in system data structure form"); |
|
56 endif |
|
57 |
|
58 sys = sysupdate(sys,"ss"); |
|
59 [n_tot,st_c,st_d,y_c,y_d] = syscont_disc(sys); # get ranges |
|
60 |
3381
|
61 ## assume there's nothing there; build partitions as appropriate |
3213
|
62 Add = Adc = Bdd = Cdd = Cdc = Ddd = []; |
|
63 |
|
64 if(isempty(st_d) & isempty(y_d)) |
|
65 error("sysdisc: expecting discrete states and/or continous outputs"); |
|
66 elseif (isempty(st_d)) |
|
67 warning("sysdisc: no discrete states"); |
|
68 elseif(isempty(y_d)) |
|
69 warning("sysdisc: no discrete outputs"); |
|
70 endif |
|
71 |
3228
|
72 [aa,bb,cc,dd] = sys2ss(sys); |
3213
|
73 if(!isempty(st_d) ) |
3228
|
74 Add = aa( st_d , st_d); |
|
75 stname = sysgetsignals(sys,"st",st_d); |
|
76 Bdd = bb( st_d , :); |
3213
|
77 if(!isempty(st_c)) |
3228
|
78 Adc = aa( st_d , st_c); |
3213
|
79 endif |
|
80 if(!isempty(y_d)) |
3228
|
81 Cdd = cc(y_d , st_d); |
3213
|
82 endif |
|
83 else |
|
84 stname = []; |
|
85 endif |
|
86 if(!isempty(y_d)) |
3228
|
87 Ddd = dd(y_d , :); |
|
88 outname = sysgetsignals(sys,"out",y_d); |
3213
|
89 if(!isempty(st_c)) |
3228
|
90 Cdc = cc(y_d , st_c); |
3213
|
91 endif |
|
92 else |
|
93 outname=[]; |
|
94 endif |
3228
|
95 inname = sysgetsignals(sys,"in"); |
3213
|
96 outlist = 1:rows(outname); |
|
97 |
|
98 if(!isempty(outname)) |
3228
|
99 tsam = sysgettsam(sys); |
|
100 [nc,nz] = sysdimensions(sys); |
|
101 dsys = ss2sys(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist); |
3213
|
102 else |
|
103 dsys=[]; |
|
104 endif |
3383
|
105 |
3213
|
106 empty_list_elements_ok = save_empty; |
|
107 |
|
108 endfunction |