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