annotate scripts/control/system/sysdisc.m @ 5443:ec8c33dcd1bf

[project @ 2005-09-08 01:40:57 by jwe]
author jwe
date Thu, 08 Sep 2005 01:40:58 +0000
parents 4c8a2e4e0717
children e9cde940b271
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1996 Auburn University. All rights reserved.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
2 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
4 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by the
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
7 ## Free Software Foundation; either version 2, or (at your option) any
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
8 ## later version.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
9 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
13 ## for more details.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
14 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5016
diff changeset
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 5016
diff changeset
18 ## 02110-1301 USA.
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
19
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3438
diff changeset
21 ## @deftypefn {Function File} {[@var{dsys}, @var{adc}, @var{cdc}] =} sysdisc (@var{sys})
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
22 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
23 ## @strong{Input}
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
24 ## @table @var
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
25 ## @item sys
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
26 ## System data structure.
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
27 ## @end table
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
28 ##
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
29 ## @strong{Outputs}
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
30 ## @table @var
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
31 ## @item dsys
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
32 ## Purely discrete portion of sys (returned empty if there is
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
33 ## no purely discrete path from inputs to outputs).
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3438
diff changeset
34 ## @item adc
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3438
diff changeset
35 ## @itemx cdc
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
36 ## Connections from continuous states to discrete states and discrete.
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
37 ## outputs, respectively.
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
38 ## @end table
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
39 ## @end deftypefn
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
40
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
41 function [dsys, Adc, Cdc] = sysdisc (sys)
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
42
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
43 save_warn_empty_list_elements = warn_empty_list_elements;
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
44 unwind_protect
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
45 warn_empty_list_elements = 0;
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
46
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
47 if (nargin != 1)
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
48 usage("[dsys,Adc,Cdc] = sysdisc(sys)");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
49 elseif (!isstruct(sys))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
50 error("sys must be in system data structure form");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
51 endif
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
52
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
53 sys = sysupdate (sys, "ss");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
54 [n_tot, st_c, st_d, y_c, y_d] = __syscont_disc__ (sys); # get ranges
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
55
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
56 ## assume there's nothing there; build partitions as appropriate
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
57 Add = Adc = Bdd = Cdd = Cdc = Ddd = [];
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
58
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
59 if(isempty(st_d) & isempty(y_d))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
60 error("sysdisc: expecting discrete states and/or continous outputs");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
61 elseif (isempty(st_d))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
62 warning("sysdisc: no discrete states");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
63 elseif(isempty(y_d))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
64 warning("sysdisc: no discrete outputs");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
65 endif
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
66
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
67 [aa,bb,cc,dd] = sys2ss(sys);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
68 if(!isempty(st_d) )
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
69 Add = aa( st_d , st_d);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
70 stname = sysgetsignals(sys,"st",st_d);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
71 Bdd = bb( st_d , :);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
72 if(!isempty(st_c))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
73 Adc = aa( st_d , st_c);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
74 endif
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
75 if(!isempty(y_d))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
76 Cdd = cc(y_d , st_d);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
77 endif
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
78 else
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
79 stname = [];
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
80 endif
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
81 if(!isempty(y_d))
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
82 Ddd = dd(y_d , :);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
83 outname = sysgetsignals(sys,"out",y_d);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
84 if(!isempty(st_c))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
85 Cdc = cc(y_d , st_c);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
86 endif
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
87 else
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
88 outname=[];
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
89 endif
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
90 inname = sysgetsignals(sys,"in");
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
91 outlist = 1:rows(outname);
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
92
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
93 if(!isempty(outname))
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
94 tsam = sysgettsam(sys);
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
95 [nc,nz] = sysdimensions(sys);
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4460
diff changeset
96 dsys = ss(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist);
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
97 else
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
98 dsys=[];
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
99 endif
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
100
4460
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
101 unwind_protect_cleanup
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
102 warn_empty_list_elements = save_warn_empty_list_elements;
cef48c4b902d [project @ 2003-07-11 18:37:48 by jwe]
jwe
parents: 4030
diff changeset
103 end_unwind_protect
3430
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
104
65b3519ac3a1 [project @ 2000-01-14 03:44:03 by jwe]
jwe
parents:
diff changeset
105 endfunction