7017
|
1 ## Copyright (C) 1996, 2000, 2002, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
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 |
7135
|
48 if (nargin < 1 || nargin > 2) |
6046
|
49 print_usage (); |
3430
|
50 endif |
|
51 |
7135
|
52 if (isempty (sys)) |
3430
|
53 retsys = sys; |
7135
|
54 error ("sysout: empty system") |
3430
|
55 return; |
|
56 endif |
|
57 |
7135
|
58 if (! isstruct (sys)) |
|
59 error ("sysout: input must be a system structure") |
3430
|
60 endif |
|
61 |
|
62 ## set up output type array |
7135
|
63 if (nargin == 1) |
|
64 opt = sysgettype (sys); |
|
65 elseif (! (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\""); |
3430
|
68 endif |
|
69 |
|
70 ## now check output for each form: |
7135
|
71 [nn, nz, mm, pp] = sysdimensions(sys); |
|
72 if (mm > 0) |
|
73 disp ("Input(s)") |
|
74 disp (__outlist__ (sysgetsignals (sys, "in"), " ")); |
3430
|
75 else |
7135
|
76 disp ("Input(s): none"); |
3430
|
77 endif |
|
78 if (pp > 0) |
7135
|
79 disp ("Output(s):") |
|
80 disp (__outlist__ (sysgetsignals (sys, "out"), |
|
81 " ", sysgetsignals (sys, "yd")) ); |
3430
|
82 else |
7135
|
83 disp ("Output(s): none"); |
3430
|
84 endif |
7135
|
85 if (sysgettsam (sys) > 0) |
|
86 disp ("Sampling interval: %g", sysgettsam (sys)); |
3430
|
87 str = "z"; |
|
88 else |
|
89 str = "s"; |
|
90 endif |
|
91 |
|
92 ## transfer function form |
7135
|
93 if (strcmp (opt, "tf") || strcmp (opt, "all")) |
|
94 sys = sysupdate (sys, "tf"); #make sure tf is up to date |
|
95 disp ("transfer function form:") |
|
96 [num, den] = sys2tf (sys); |
|
97 tfout (num, den, str); |
3430
|
98 endif |
|
99 |
7135
|
100 if (strcmp(opt, "zp") || strcmp(opt, "all")) |
|
101 sys = sysupdate (sys, "zp"); #make sure zp is up to date |
3430
|
102 disp("zero-pole form:") |
7135
|
103 [zer, pol, kk] = sys2zp (sys); |
|
104 zpout (zer, pol, kk, str) |
3430
|
105 endif |
|
106 |
7135
|
107 if (strcmp(opt, "ss") || strcmp(opt, "all")) |
|
108 sys = sysupdate (sys, "ss"); |
|
109 disp ("state-space form:"); |
|
110 disp ("%d continuous states, %d discrete states", nn, nz); |
|
111 if (nn+nz > 0) |
|
112 disp ("State(s):") |
3430
|
113 xi = (nn+1):(nn+nz); |
7135
|
114 xd = zeros (1, nn+nz); |
|
115 if (! isempty (xi)) |
3430
|
116 xd(xi) = 1; |
|
117 endif |
7135
|
118 disp (__outlist__ (sysgetsignals (sys, "st"), " ", xd)); |
3430
|
119 else |
7135
|
120 disp ("State(s): none"); |
3430
|
121 endif |
|
122 |
|
123 ## display matrix values? |
7135
|
124 dmat = (max ([nn+nz, mm, pp]) <= 32); |
3430
|
125 |
7135
|
126 printf ("A matrix: %d x %d\n", sysdimensions (sys, "st"), |
|
127 sysdimensions (sys, "st")); |
|
128 [aa, bb, cc, dd] = sys2ss (sys); |
|
129 if (dmat) |
|
130 disp (aa); |
|
131 endif |
3430
|
132 |
7135
|
133 printf ("B matrix: %d x %d\n", sysdimensions (sys, "st"), |
|
134 sysdimensions (sys, "in")); |
|
135 if (dmat) |
|
136 disp (bb); |
|
137 endif |
3430
|
138 |
7135
|
139 printf ("C matrix: %d x %d\n", sysdimensions (sys, "out"), |
|
140 sysdimensions (sys, "st")); |
|
141 if (dmat) |
|
142 disp (cc); |
|
143 endif |
3430
|
144 |
7135
|
145 printf("D matrix: %d x %d\n", sysdimensions (sys, "out"), |
|
146 sysdimensions (sys, "in")); |
|
147 if (dmat) |
|
148 disp (dd); |
|
149 endif |
3430
|
150 endif |
|
151 |
7133
|
152 if (nargout >= 1) |
3430
|
153 retsys = sys; |
|
154 endif |
|
155 |
|
156 endfunction |