3430
|
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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
3500
|
21 ## @deftypefn {Function File} {} sysout (@var{sys}, @var{opt}) |
3430
|
22 ## print out a system data structure in desired format |
|
23 ## @table @var |
|
24 ## @item sys |
|
25 ## system data structure |
|
26 ## @item opt |
|
27 ## Display option |
|
28 ## @table @code |
|
29 ## @item [] |
3439
|
30 ## primary system form (default) |
3430
|
31 ## @item "ss" |
|
32 ## state space form |
|
33 ## @item "tf" |
|
34 ## transfer function form |
|
35 ## @item "zp" |
|
36 ## zero-pole form |
|
37 ## @item "all" |
|
38 ## all of the above |
|
39 ## @end table |
|
40 ## @end table |
|
41 ## @end deftypefn |
|
42 |
|
43 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
44 ## Created: 1995-1996 |
|
45 |
|
46 function retsys = sysout (sys, opt) |
|
47 |
|
48 if( (nargin < 1) || (nargin > 2) ) |
6046
|
49 print_usage (); |
3430
|
50 endif |
|
51 |
|
52 if(isempty(sys)) |
|
53 retsys = sys; |
|
54 warning("sysout: empty system") |
|
55 return; |
|
56 endif |
|
57 |
4030
|
58 if(! isstruct(sys)) |
3430
|
59 disp("sysout: input must be a system structure") |
|
60 endif |
|
61 |
|
62 ## set up output type array |
|
63 if( nargin == 1 ) |
|
64 opt = sysgettype(sys); |
|
65 else |
|
66 if( ! (strcmp(opt,"ss") + strcmp(opt,"tf") + ... |
|
67 strcmp(opt,"zp") + strcmp(opt,"all") ) ) |
|
68 error("opt must be one of [], \"ss\", \"tf\", \"zp\", or \"all\""); |
|
69 endif |
|
70 endif |
|
71 |
|
72 ## now check output for each form: |
|
73 [nn,nz,mm,pp] = sysdimensions(sys); |
|
74 if( mm > 0) |
|
75 disp("Input(s)") |
3438
|
76 disp(__outlist__(sysgetsignals(sys,"in")," ")); |
3430
|
77 else |
|
78 disp("Input(s): none"); |
|
79 endif |
|
80 if (pp > 0) |
|
81 disp("Output(s):") |
3438
|
82 disp(__outlist__(sysgetsignals(sys,"out"), ... |
3430
|
83 " ",sysgetsignals(sys,"yd")) ); |
|
84 else |
|
85 disp("Output(s): none"); |
|
86 endif |
|
87 if(sysgettsam(sys) > 0) |
|
88 disp(["Sampling interval: ",num2str(sysgettsam(sys))]); |
|
89 str = "z"; |
|
90 else |
|
91 str = "s"; |
|
92 endif |
|
93 |
|
94 ## transfer function form |
|
95 if( strcmp(opt,"tf") + strcmp(opt,"all") ) |
|
96 sys = sysupdate(sys,"tf"); #make sure tf is up to date |
|
97 disp("transfer function form:") |
|
98 [num,den] = sys2tf(sys); |
|
99 tfout(num,den,str); |
|
100 endif |
|
101 |
|
102 if( strcmp(opt,"zp") + strcmp(opt,"all") ) |
|
103 sys = sysupdate(sys,"zp"); #make sure zp is up to date |
|
104 disp("zero-pole form:") |
|
105 [zer,pol,kk] = sys2zp(sys); |
|
106 zpout(zer, pol, kk,str) |
|
107 endif |
|
108 |
|
109 if( strcmp(opt,"ss") + strcmp(opt,"all") ) |
|
110 sys = sysupdate(sys,"ss"); |
|
111 disp("state-space form:"); |
|
112 disp([num2str(nn)," continuous states, ", num2str(nz)," discrete states"]); |
|
113 if( nn+nz > 0) |
|
114 disp("State(s):") |
|
115 xi = (nn+1):(nn+nz); |
|
116 xd = zeros(1,nn+nz); |
|
117 if(!isempty(xi)) |
|
118 xd(xi) = 1; |
|
119 endif |
3438
|
120 disp(__outlist__(sysgetsignals(sys,"st")," ",xd)); |
3430
|
121 else |
|
122 disp("State(s): none"); |
|
123 endif |
|
124 |
|
125 ## display matrix values? |
|
126 dmat = (max( [ (nn+nz), mm, pp ] ) <= 32); |
|
127 |
|
128 printf("A matrix: %d x %d\n",sysdimensions(sys,"st"), |
|
129 sysdimensions(sys,"st")); |
|
130 [aa,bb,cc,dd] = sys2ss(sys); |
|
131 if(dmat) disp(aa); endif |
|
132 |
|
133 printf("B matrix: %d x %d\n",sysdimensions(sys,"st"), |
|
134 sysdimensions(sys,"in")); |
|
135 if(dmat) disp(bb); endif |
|
136 |
|
137 printf("C matrix: %d x %d\n",sysdimensions(sys,"out"), |
|
138 sysdimensions(sys,"st")); |
|
139 if(dmat) disp(cc); endif |
|
140 |
|
141 printf("D matrix: %d x %d\n",sysdimensions(sys,"out"), |
|
142 sysdimensions(sys,"in")); |
|
143 if(dmat) disp(dd); endif |
|
144 endif |
|
145 |
|
146 if(nargout >= 1) |
|
147 retsys = sys; |
|
148 endif |
|
149 |
|
150 ## restore global variable |
|
151 |
|
152 endfunction |