3431
|
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} {@var{outputs} =} rldemo (@var{inputs}) |
|
21 ##Octave Controls toolbox demo: Root Locus demo |
|
22 ##@end deftypefn |
|
23 |
|
24 ## Author: David Clem |
|
25 ## Created: August 15, 1994 |
|
26 ## Updated by John Ingram December 1996 |
|
27 |
|
28 function rldemo () |
|
29 |
|
30 while (1) |
|
31 clc |
|
32 k = menu("Octave Root Locus Demo", ... |
|
33 "Display continuous system's open loop poles and zeros (pzmap)", ... |
|
34 "Display discrete system's open loop poles and zeros (pzmap)", ... |
|
35 "Display root locus diagram of SISO continuous system (rlocus)", ... |
|
36 "Display root locus diagram of SISO discrete system (rlocus)", ... |
|
37 "Return to main demo menu"); |
|
38 gset autoscale |
|
39 if (k == 1) |
|
40 clc |
|
41 help pzmap |
|
42 prompt |
|
43 |
|
44 clc |
|
45 disp("Display continuous system's open loop poles and zeros (pzmap)\n"); |
|
46 disp("Example #1, Consider the following continuous transfer function:"); |
|
47 cmd = "sys1 = tf2sys([1.5, 18.5, 6], [1, 4, 155, 302, 5050]);"; |
|
48 disp(cmd); |
|
49 eval(cmd); |
|
50 cmd ="sysout(sys1);"; |
|
51 disp(cmd); |
|
52 eval(cmd); |
|
53 disp("\nPole-zero form can be obtained as follows:"); |
|
54 cmd = "sysout(sys1,""zp"");"; |
|
55 disp(cmd); |
|
56 eval(cmd); |
|
57 disp("View the system's open loop poles and zeros with the command:") |
|
58 cmd = "pzmap(sys1);"; |
|
59 run_cmd |
|
60 prompt |
|
61 |
|
62 clc |
|
63 disp("Example #2, Consider the following set of poles and zeros:"); |
|
64 cmd = "sys2 = zp2sys([-1, 5, -23],[-1, -10, -7+5i, -7-5i],5);"; |
|
65 disp(cmd); |
|
66 eval(cmd); |
|
67 cmd = "sysout(sys2);"; |
|
68 disp(cmd); |
|
69 eval(cmd); |
|
70 disp("\nThe pzmap command for the zp form is the same as the tf form:") |
|
71 cmd = "pzmap(sys2);"; |
|
72 run_cmd; |
|
73 disp("\nThe internal representation of the system is not important;"); |
|
74 disp("pzmap automatically sorts it out internally."); |
|
75 prompt; |
|
76 |
|
77 clc |
|
78 disp("Example #3, Consider the following state space system:\n"); |
|
79 cmd = "sys3=ss2sys([0, 1; -10, -11], [0; 1], [0, -2], 1);"; |
|
80 disp(cmd); |
|
81 eval(cmd); |
|
82 cmd = "sysout(sys3);"; |
|
83 disp(cmd); |
|
84 eval(cmd); |
|
85 disp("\nPole-zero form can be obtained as follows:"); |
|
86 cmd = "sysout(sys3,""zp"");"; |
|
87 disp(cmd); |
|
88 eval(cmd); |
|
89 disp("\nOnce again, the pzmap command is the same:"); |
|
90 cmd = "pzmap(sys3);"; |
|
91 run_cmd; |
|
92 prompt; |
|
93 |
|
94 closeplot |
|
95 clc |
|
96 |
|
97 elseif (k == 2) |
|
98 clc |
|
99 help pzmap |
|
100 prompt |
|
101 |
|
102 clc |
|
103 disp("\nDisplay discrete system's open loop poles and zeros (pzmap)\n"); |
|
104 disp("First we must define a sampling time, as follows:\n"); |
|
105 cmd = "Tsam = 1;"; |
|
106 run_cmd; |
|
107 disp("Example #1, Consider the following discrete transfer function:"); |
|
108 cmd = "sys1 = tf2sys([1.05, -0.09048], [1, -2, 1],Tsam);"; |
|
109 disp(cmd); |
|
110 eval(cmd); |
|
111 cmd ="sysout(sys1);"; |
|
112 disp(cmd); |
|
113 eval(cmd); |
|
114 disp("\nPole-zero form can be obtained as follows:"); |
|
115 cmd = "sysout(sys1,""zp"");"; |
|
116 disp(cmd); |
|
117 eval(cmd); |
|
118 disp("View the system's open loop poles and zeros with the command:") |
|
119 cmd = "pzmap(sys1);"; |
|
120 run_cmd |
|
121 prompt |
|
122 |
|
123 clc |
|
124 disp("Example #2, Consider the following set of discrete poles and zeros:"); |
|
125 cmd = "sys2 = zp2sys(-0.717, [1, -0.368], 3.68, Tsam);"; |
|
126 disp(cmd); |
|
127 eval(cmd); |
|
128 cmd = "sysout(sys2);"; |
|
129 disp(cmd); |
|
130 eval(cmd); |
|
131 disp("\nThe pzmap command for the zp form is the same as the tf form:") |
|
132 cmd = "pzmap(sys2);"; |
|
133 run_cmd; |
|
134 disp("\nThe internal representation of the system is not important;"); |
|
135 disp("pzmap automatically sorts it out internally."); |
|
136 prompt; |
|
137 |
|
138 clc |
|
139 disp("Example #3, Consider the following discrete state space system:\n"); |
|
140 cmd = "sys3=ss2sys([1, 0.0952; 0, 0.905], [0.00484; 0.0952], [1, 0], 0, Tsam);"; |
|
141 disp(cmd); |
|
142 eval(cmd); |
|
143 cmd = "sysout(sys3);"; |
|
144 disp(cmd); |
|
145 eval(cmd); |
|
146 disp("\nPole-zero form can be obtained as follows:"); |
|
147 cmd = "sysout(sys3,""zp"");"; |
|
148 disp(cmd); |
|
149 eval(cmd); |
|
150 disp("\nOnce again, the pzmap command is the same:"); |
|
151 cmd = "pzmap(sys3);"; |
|
152 run_cmd; |
|
153 prompt; |
|
154 |
|
155 closeplot |
|
156 clc |
|
157 |
|
158 elseif (k == 3) |
|
159 clc |
|
160 help rlocus |
|
161 prompt; |
|
162 |
|
163 clc |
|
164 disp("Display root locus of a continuous SISO system (rlocus)\n") |
|
165 disp("Example #1, Consider the following continuous transfer function:"); |
|
166 cmd = "sys1 = tf2sys([1.5, 18.5, 6],[1, 4, 155, 302, 5050]);"; |
|
167 disp(cmd); |
|
168 eval(cmd); |
|
169 cmd ="sysout(sys1);"; |
|
170 disp(cmd); |
|
171 eval(cmd); |
|
172 disp("\nPole-zero form can be obtained as follows:"); |
|
173 cmd = "sysout(sys1,""zp"");"; |
|
174 disp(cmd); |
|
175 eval(cmd); |
|
176 disp("\nWhen using rlocus, inital system poles are displayed as X's.") |
|
177 disp("Moving poles are displayed as diamonds. Zeros are displayed as") |
|
178 disp("boxes. The simplest form of the rlocus command is as follows:") |
|
179 cmd = "rlocus(sys1);"; |
|
180 run_cmd |
|
181 disp("\nrlocus automatically selects the minimum and maximum gains based") |
|
182 disp("on the real-axis locus breakpoints. The plot limits are chosen") |
|
183 disp("to be no more than 10 times the maximum magnitude of the open") |
|
184 disp("loop poles/zeros."); |
|
185 prompt |
|
186 |
|
187 clc |
|
188 disp("Example #2, Consider the following set of poles and zeros:"); |
|
189 cmd = "sys2 = zp2sys([],[0, -20, -2, -0.1],5);"; |
|
190 disp(cmd); |
|
191 eval(cmd); |
|
192 cmd = "sysout(sys2);"; |
|
193 disp(cmd); |
|
194 eval(cmd); |
|
195 disp("\nThe rlocus command for the zp form is the same as the tf form:") |
|
196 cmd = "rlocus(sys2);"; |
|
197 run_cmd; |
|
198 disp("\nThe internal representation of the system is not important;"); |
|
199 disp("rlocus automatically sorts it out internally."); |
|
200 prompt; |
|
201 |
|
202 clc |
|
203 disp("Example #3, Consider the following state space system:\n"); |
|
204 cmd = "sys3=ss2sys([0, 1; -10, -11], [0; 1], [0, -2], 0);"; |
|
205 disp(cmd); |
|
206 eval(cmd); |
|
207 cmd = "sysout(sys3);"; |
|
208 disp(cmd); |
|
209 eval(cmd); |
|
210 disp("\nPole-zero form can be obtained as follows:"); |
|
211 cmd = "sysout(sys3,""zp"");"; |
|
212 disp(cmd); |
|
213 eval(cmd); |
|
214 disp("\nOnce again, the rlocus command is the same:"); |
|
215 cmd = "rlocus(sys3);"; |
|
216 run_cmd; |
|
217 |
|
218 disp("\nNo matter what form the system is in, the rlocus command works the"); |
|
219 disp("the same."); |
|
220 prompt; |
|
221 |
|
222 closeplot |
|
223 clc |
|
224 |
|
225 elseif (k == 4) |
|
226 clc |
|
227 help rlocus |
|
228 prompt |
|
229 |
|
230 clc |
|
231 disp("Display root locus of a discrete SISO system (rlocus)\n") |
|
232 disp("First we must define a sampling time, as follows:\n"); |
|
233 cmd = "Tsam = 1;"; |
|
234 run_cmd; |
|
235 disp("Example #1, Consider the following discrete transfer function:"); |
|
236 cmd = "sys1 = tf2sys([1.05, -0.09048],[1, -2, 1],Tsam);"; |
|
237 disp(cmd); |
|
238 eval(cmd); |
|
239 cmd ="sysout(sys1);"; |
|
240 disp(cmd); |
|
241 eval(cmd); |
|
242 disp("\nPole-zero form can be obtained as follows:"); |
|
243 cmd = "sysout(sys1,""zp"");"; |
|
244 disp(cmd); |
|
245 eval(cmd); |
|
246 disp("\nWhen using rlocus, inital system poles are displayed as X's.") |
|
247 disp("Moving poles are displayed as diamonds. Zeros are displayed as") |
|
248 disp("boxes. The simplest form of the rlocus command is as follows:") |
|
249 cmd = "rlocus(sys1);"; |
|
250 run_cmd |
|
251 disp("\nrlocus automatically selects the minimum and maximum gains based") |
|
252 disp("on the real-axis locus breakpoints. The plot limits are chosen") |
|
253 disp("to be no more than 10 times the maximum magnitude of the open") |
|
254 disp("loop poles/zeros."); |
|
255 prompt |
|
256 |
|
257 clc |
|
258 disp("Example #2, Consider the following set of discrete poles and zeros:"); |
|
259 cmd = "sys2 = zp2sys(-0.717, [1, -0.368], 3.68, Tsam);"; |
|
260 disp(cmd); |
|
261 eval(cmd); |
|
262 cmd = "sysout(sys2);"; |
|
263 disp(cmd); |
|
264 eval(cmd); |
|
265 disp("\nThe rlocus command for the zp form is the same as the tf form:") |
|
266 cmd = "rlocus(sys2);"; |
|
267 run_cmd; |
|
268 disp("\nThe internal representation of the system is not important;"); |
|
269 disp("rlocus automatically sorts it out internally. Also, it does not"); |
|
270 disp("matter if the system is continuous or discrete. rlocus also sorts"); |
|
271 disp("this out automatically"); |
|
272 prompt; |
|
273 |
|
274 clc |
|
275 disp("Example #3, Consider the following discrete state space system:\n"); |
|
276 cmd = "sys3=ss2sys([1, 0.0952; 0, 0.905], [0.00484; 0.0952], [1, 0], 0, Tsam);"; |
|
277 disp(cmd); |
|
278 eval(cmd); |
|
279 cmd = "sysout(sys3);"; |
|
280 disp(cmd); |
|
281 eval(cmd); |
|
282 disp("\nPole-zero form can be obtained as follows:"); |
|
283 cmd = "sysout(sys3,""zp"");"; |
|
284 disp(cmd); |
|
285 eval(cmd); |
|
286 disp("\nOnce again, the rlocus command is the same:"); |
|
287 cmd = "rlocus(sys3);"; |
|
288 run_cmd; |
|
289 |
|
290 disp("\nNo matter what form the system is in, the rlocus command works the"); |
|
291 disp("the same."); |
|
292 |
|
293 prompt; |
|
294 |
|
295 closeplot |
|
296 clc |
|
297 |
|
298 elseif (k == 5) |
|
299 return |
|
300 endif |
|
301 endwhile |
|
302 endfunction |