comparison scripts/control/system/sysrepdemo.m @ 4771:b8105302cfe8

[project @ 2004-02-16 17:45:50 by jwe]
author jwe
date Mon, 16 Feb 2004 17:45:50 +0000
parents 65b3519ac3a1
children 4c8a2e4e0717
comparison
equal deleted inserted replaced
4770:ef5e598f099b 4771:b8105302cfe8
43 ch_quit = ch_details+1; 43 ch_quit = ch_details+1;
44 while(syschoice != ch_quit) 44 while(syschoice != ch_quit)
45 disp(" ") 45 disp(" ")
46 syschoice = menu("Octave System Representation Menu", ... 46 syschoice = menu("Octave System Representation Menu", ...
47 "General overview of system representation (DO THIS FIRST)", ... 47 "General overview of system representation (DO THIS FIRST)", ...
48 "Initialize a system (ss2sys, tf2sys, zp2sys)", ... 48 "Initialize a system (ss, tf, zp)", ...
49 "Extract data from a system(sys2ss, sys2tf, sys2zp, etc.)", ... 49 "Extract data from a system(sys2ss, sys2tf, sys2zp, etc.)", ...
50 "Update internal representation (sysupdate)", ... 50 "Update internal representation (sysupdate)", ...
51 "View the internal contents of a system (sysout)", ... 51 "View the internal contents of a system (sysout)", ...
52 "Details of internal representation", ... 52 "Details of internal representation", ...
53 "Return to main menu"); 53 "Return to main menu");
77 disp("in correcting their programming errors while using the OCST.") 77 disp("in correcting their programming errors while using the OCST.")
78 disp("The details of the internal representation can be seen in "); 78 disp("The details of the internal representation can be seen in ");
79 disp(["menu option ",num2str(ch_details)]); 79 disp(["menu option ",num2str(ch_details)]);
80 disp("The data structure used in the OCST is called a \"system data structure.\""); 80 disp("The data structure used in the OCST is called a \"system data structure.\"");
81 disp("A system data structure is contstructed with one of:") 81 disp("A system data structure is contstructed with one of:")
82 disp(" fir2sys (FIR transfer function to system)") 82 disp(" fir (FIR transfer function to system)")
83 disp(" ss2sys (state space matrices to system)") 83 disp(" ss (state space matrices to system)")
84 disp(" tf2sys (SISO transfer function to system)") 84 disp(" tf (SISO transfer function to system)")
85 disp(" zp2sys (SISO zero/pole/leading coefficient to system)") 85 disp(" zp (SISO zero/pole/leading coefficient to system)")
86 disp(" ") 86 disp(" ")
87 disp(["These functions are discussed in in menu option ",num2str(ch_init)]) 87 disp(["These functions are discussed in in menu option ",num2str(ch_init)])
88 disp("The data in a system may be extracted using ") 88 disp("The data in a system may be extracted using ")
89 disp(" sys2fir (FIR transfer function from system") 89 disp(" sys2fir (FIR transfer function from system")
90 disp(" sys2ss (state space matrices from system)") 90 disp(" sys2ss (state space matrices from system)")
104 disp(" "); 104 disp(" ");
105 formopt = 0; 105 formopt = 0;
106 while(formopt != 4) 106 while(formopt != 4)
107 disp("Three data formats may be used to initialize a system:") 107 disp("Three data formats may be used to initialize a system:")
108 formopt = menu("System data structure initialization menu", ... 108 formopt = menu("System data structure initialization menu", ...
109 "State space form (ss2sys)", ... 109 "State space form (ss)", ...
110 "Transfer function form (tf2sys)", ... 110 "Transfer function form (tf)", ...
111 "zero-pole form (zp2sys)", ... 111 "zero-pole form (zp)", ...
112 "Return to System representation menu"); 112 "Return to System representation menu");
113 if(formopt == 1) 113 if(formopt == 1)
114 disp("State space representation of a system is based on the usual") 114 disp("State space representation of a system is based on the usual")
115 disp("multi-variable differential equations") 115 disp("multi-variable differential equations")
116 disp(" ") 116 disp(" ")
125 while(ssopt < ssquit) 125 while(ssopt < ssquit)
126 ssopt = menu("State space initialization examples", ... 126 ssopt = menu("State space initialization examples", ...
127 "Double integrator example", ... 127 "Double integrator example", ...
128 "Double delay (discrete-time) example", ... 128 "Double delay (discrete-time) example", ...
129 "Summing junction (D-matrix only) example", ... 129 "Summing junction (D-matrix only) example", ...
130 "ss2sys details (help ss2sys)", ... 130 "ss details (help ss)", ...
131 "return to system initialization menu", ... 131 "return to system initialization menu", ...
132 "return to system representation main menu"); 132 "return to system representation main menu");
133 if(ssopt == 1) 133 if(ssopt == 1)
134 disp("Example: construct a system representation of a") 134 disp("Example: construct a system representation of a")
135 disp("double integrator via state-space form") 135 disp("double integrator via state-space form")
137 run_cmd 137 run_cmd
138 cmd = "b = [0; 1];"; 138 cmd = "b = [0; 1];";
139 run_cmd 139 run_cmd
140 cmd = "c = [1, 0];"; 140 cmd = "c = [1, 0];";
141 run_cmd 141 run_cmd
142 cmd = "sys = ss2sys(a,b,c);"; 142 cmd = "sys = ss(a,b,c);";
143 run_cmd 143 run_cmd
144 disp("The state space form of the system is seen via sysout:") 144 disp("The state space form of the system is seen via sysout:")
145 cmd = "sysout(sys)"; 145 cmd = "sysout(sys)";
146 run_cmd 146 run_cmd
147 disp("Notice that the Octave controls toolbox automatically") 147 disp("Notice that the Octave controls toolbox automatically")
160 run_cmd 160 run_cmd
161 cmd = "b = [0; 1];"; 161 cmd = "b = [0; 1];";
162 run_cmd 162 run_cmd
163 cmd = "c = [1, 0];"; 163 cmd = "c = [1, 0];";
164 run_cmd 164 run_cmd
165 cmd = "sys=ss2sys(a,b,c,[],1e-3);"; 165 cmd = "sys=ss(a,b,c,[],1e-3);";
166 run_cmd 166 run_cmd
167 cmd = "sysout(sys)"; 167 cmd = "sysout(sys)";
168 run_cmd 168 run_cmd
169 disp("Notice that the D matrix was filled in automatically.") 169 disp("Notice that the D matrix was filled in automatically.")
170 disp("This is done if D is input as the empty matrix.") 170 disp("This is done if D is input as the empty matrix.")
197 disp("A summing junction that computes e(t) = r(t) - y(t) may be"); 197 disp("A summing junction that computes e(t) = r(t) - y(t) may be");
198 disp("constructed as follows:"); 198 disp("constructed as follows:");
199 disp("First, we set the matrix D:") 199 disp("First, we set the matrix D:")
200 cmd = "D = [1, -1];"; 200 cmd = "D = [1, -1];";
201 run_cmd 201 run_cmd
202 disp("ss2sys allows the initialization of signal and state names") 202 disp("ss allows the initialization of signal and state names")
203 disp("(see option 4), so we initialize these as follows:") 203 disp("(see option 4), so we initialize these as follows:")
204 cmd = "inname = list(\"r(t)\",\"y(t)\");"; 204 cmd = "inname = {\"r(t)\",\"y(t)\"};";
205 run_cmd; 205 run_cmd;
206 cmd = "outname = \"e(t)\";"; 206 cmd = "outname = \"e(t)\";";
207 run_cmd 207 run_cmd
208 disp("Since the system is continous time and without states,") 208 disp("Since the system is continous time and without states,")
209 disp("the ss2sys inputs tsam, n, and nz are all zero:") 209 disp("the ss inputs tsam, n, and nz are all zero:")
210 cmd = "sys = ss2sys([],[],[],D,0,0,0,[],inname,outname);"; 210 cmd = "sys = ss([],[],[],D,0,0,0,[],inname,outname);";
211 run_cmd 211 run_cmd
212 disp("The resulting system is:") 212 disp("The resulting system is:")
213 cmd = "sysout(sys)"; 213 cmd = "sysout(sys)";
214 run_cmd 214 run_cmd
215 disp("A discrete-time summing block can be implemented by setting") 215 disp("A discrete-time summing block can be implemented by setting")
216 disp("the sampling time positive:") 216 disp("the sampling time positive:")
217 cmd = "sys = ss2sys([],[],[],D,1e-3,0,0,[],inname,outname);"; 217 cmd = "sys = ss([],[],[],D,1e-3,0,0,[],inname,outname);";
218 run_cmd 218 run_cmd
219 disp("The resulting system is:") 219 disp("The resulting system is:")
220 cmd = "sysout(sys)"; 220 cmd = "sysout(sys)";
221 run_cmd 221 run_cmd
222 prompt 222 prompt
223 elseif(ssopt == 4) 223 elseif(ssopt == 4)
224 help ss2sys 224 help ss
225 disp(" ") 225 disp(" ")
226 disp(" ") 226 disp(" ")
227 disp("Notice that state-space form allows a single system to have") 227 disp("Notice that state-space form allows a single system to have")
228 disp("both continuous and discrete-time states and to have both continuous") 228 disp("both continuous and discrete-time states and to have both continuous")
229 disp("and discrete-time outputs. Since it's fairly easy to make an") 229 disp("and discrete-time outputs. Since it's fairly easy to make an")
239 while(tfopt < 5) 239 while(tfopt < 5)
240 tfopt = menu("Transfer function initialization menu", ... 240 tfopt = menu("Transfer function initialization menu", ...
241 "Continuous time initialization" , ... 241 "Continuous time initialization" , ...
242 "Discrete time initialization" , ... 242 "Discrete time initialization" , ...
243 "User specified signal names" , ... 243 "User specified signal names" , ...
244 "tf2sys details (help tf2sys)", ... 244 "tf details (help tf)", ...
245 "Return to system initialization menu", ... 245 "Return to system initialization menu", ...
246 "Return to system representation main menu"); 246 "Return to system representation main menu");
247 if(tfopt == 1) # continuous time 247 if(tfopt == 1) # continuous time
248 disp("A transfer function is represented by vectors of the") 248 disp("A transfer function is represented by vectors of the")
249 disp("coefficients of the numerator and denominator polynomials"); 249 disp("coefficients of the numerator and denominator polynomials");
257 disp("is generated by the following commands:") 257 disp("is generated by the following commands:")
258 cmd = "num = [5, -1]"; 258 cmd = "num = [5, -1]";
259 run_cmd 259 run_cmd
260 cmd = "denom = [1, -2, 6]"; 260 cmd = "denom = [1, -2, 6]";
261 run_cmd 261 run_cmd
262 cmd = "sys = tf2sys(num,denom);"; 262 cmd = "sys = tf(num,denom);";
263 run_cmd 263 run_cmd
264 disp("alternatively, the system can be generated in a single command:"); 264 disp("alternatively, the system can be generated in a single command:");
265 cmd = "sys = tf2sys([5, -1], [1, -2, 6]);"; 265 cmd = "sys = tf([5, -1], [1, -2, 6]);";
266 run_cmd 266 run_cmd
267 disp("Notice the output of sys: it is an Octave data structure.") 267 disp("Notice the output of sys: it is an Octave data structure.")
268 disp("The details of its member variables are explained under") 268 disp("The details of its member variables are explained under")
269 disp("System Representation Menu option 5 (the details of system form)") 269 disp("System Representation Menu option 5 (the details of system form)")
270 disp(" "); 270 disp(" ");
277 elseif(tfopt == 2) # discrete time 277 elseif(tfopt == 2) # discrete time
278 disp("A transfer function is represented by vectors of the") 278 disp("A transfer function is represented by vectors of the")
279 disp("coefficients of the numerator and denominator polynomials"); 279 disp("coefficients of the numerator and denominator polynomials");
280 disp("Discrete-time transfer functions require ") 280 disp("Discrete-time transfer functions require ")
281 disp("the additional parameter of a sampling period:") 281 disp("the additional parameter of a sampling period:")
282 cmd = "sys=tf2sys([5, -1], [1, 2, -6], 1e-3);"; 282 cmd = "sys=tf([5, -1], [1, 2, -6], 1e-3);";
283 run_cmd 283 run_cmd
284 cmd = "sysout(sys)"; 284 cmd = "sysout(sys)";
285 run_cmd 285 run_cmd
286 disp("The OCST recognizes discrete-time transfer functions and") 286 disp("The OCST recognizes discrete-time transfer functions and")
287 disp("accordingly prints them with the frequency domain variable z."); 287 disp("accordingly prints them with the frequency domain variable z.");
292 disp("names to the signals in the other examples. We may initialize a transfer"); 292 disp("names to the signals in the other examples. We may initialize a transfer");
293 disp("function with user-specified names as follows: Consider a simple ") 293 disp("function with user-specified names as follows: Consider a simple ")
294 disp("double-integrator model of aircraft roll dynamics with ") 294 disp("double-integrator model of aircraft roll dynamics with ")
295 disp("input \"aileron angle\" and output \"theta\". A ") 295 disp("input \"aileron angle\" and output \"theta\". A ")
296 disp("system for this model is generated by the command") 296 disp("system for this model is generated by the command")
297 cmd = "aircraft=tf2sys(1, [1, 0, 0], 0,\"aileron angle\",\"theta\");"; run_cmd 297 cmd = "aircraft=tf(1, [1, 0, 0], 0,\"aileron angle\",\"theta\");"; run_cmd
298 disp("The sampling time parameter 0 indicates that the system") 298 disp("The sampling time parameter 0 indicates that the system")
299 disp("is continuous time. A positive sampling time indicates a") 299 disp("is continuous time. A positive sampling time indicates a")
300 disp("discrete-time system (or sampled data system).") 300 disp("discrete-time system (or sampled data system).")
301 cmd = "sysout(aircraft)"; 301 cmd = "sysout(aircraft)";
302 run_cmd 302 run_cmd
304 disp("These signal names are used in OCST plots and design functions."); 304 disp("These signal names are used in OCST plots and design functions.");
305 disp("(Run the frequency response demo to see an example of the use of "); 305 disp("(Run the frequency response demo to see an example of the use of ");
306 disp("signal names in plots.)") 306 disp("signal names in plots.)")
307 prompt 307 prompt
308 elseif(tfopt == 4) # help 308 elseif(tfopt == 4) # help
309 help tf2sys 309 help tf
310 prompt 310 prompt
311 elseif(tfopt == 6) # return to main menu 311 elseif(tfopt == 6) # return to main menu
312 formopt = 4; 312 formopt = 4;
313 endif 313 endif
314 endwhile 314 endwhile
317 while(zpopt < 5) 317 while(zpopt < 5)
318 zpopt = menu("Zero-pole initialization menu", ... 318 zpopt = menu("Zero-pole initialization menu", ...
319 "Continuous time initialization" , ... 319 "Continuous time initialization" , ...
320 "Discrete time initialization" , ... 320 "Discrete time initialization" , ...
321 "User specified signal names" , ... 321 "User specified signal names" , ...
322 "zp2sys details (help zp2sys)", ... 322 "zp details (help zp)", ...
323 "Return to system initialization menu", ... 323 "Return to system initialization menu", ...
324 "Return to system representation main menu"); 324 "Return to system representation main menu");
325 if(zpopt == 1) # continuous time 325 if(zpopt == 1) # continuous time
326 disp("A zero-pole form representation of a system includes vectors") 326 disp("A zero-pole form representation of a system includes vectors")
327 disp("of the system poles and zeros and a scalar leading coefficient."); 327 disp("of the system poles and zeros and a scalar leading coefficient.");
338 run_cmd 338 run_cmd
339 cmd = "denom = [1, -2, 6]"; 339 cmd = "denom = [1, -2, 6]";
340 run_cmd 340 run_cmd
341 cmd = "k = 5"; 341 cmd = "k = 5";
342 run_cmd 342 run_cmd
343 cmd = "sys = zp2sys(num,denom,k);"; 343 cmd = "sys = zp(num,denom,k);";
344 run_cmd 344 run_cmd
345 disp("alternatively, the system can be generated in a single command:"); 345 disp("alternatively, the system can be generated in a single command:");
346 cmd = "sys = zp2sys([5, -1],[1, -2, 6],5);"; 346 cmd = "sys = zp([5, -1],[1, -2, 6],5);";
347 run_cmd 347 run_cmd
348 disp("Notice the output of sys: it is an Octave data structure.") 348 disp("Notice the output of sys: it is an Octave data structure.")
349 disp("The details of its member variables are explained under") 349 disp("The details of its member variables are explained under")
350 disp("System Representation Menu option 5 (the details of system form)") 350 disp("System Representation Menu option 5 (the details of system form)")
351 disp(" "); 351 disp(" ");
358 elseif(zpopt == 2) # discrete time 358 elseif(zpopt == 2) # discrete time
359 disp("A zero-pole form representation of a system includes vectors") 359 disp("A zero-pole form representation of a system includes vectors")
360 disp("of the system poles and zeros and a scalar leading coefficient."); 360 disp("of the system poles and zeros and a scalar leading coefficient.");
361 disp(" ") 361 disp(" ")
362 disp("Discrete-time systems require the additional parameter of a sampling period:") 362 disp("Discrete-time systems require the additional parameter of a sampling period:")
363 cmd = "sys=zp2sys([5, -1],[1, 2, -6],5,1e-3);"; 363 cmd = "sys=zp([5, -1],[1, 2, -6],5,1e-3);";
364 run_cmd 364 run_cmd
365 cmd = "sysout(sys)"; 365 cmd = "sysout(sys)";
366 run_cmd 366 run_cmd
367 disp("The OCST recognizes discrete-time transfer functions and") 367 disp("The OCST recognizes discrete-time transfer functions and")
368 disp("accordingly prints them with the frequency domain variable z."); 368 disp("accordingly prints them with the frequency domain variable z.");
373 disp("names to the signals in the other examples. We may initialize a transfer"); 373 disp("names to the signals in the other examples. We may initialize a transfer");
374 disp("function with user-specified names as follows: Consider a simple ") 374 disp("function with user-specified names as follows: Consider a simple ")
375 disp("double-integrator model of aircraft roll dynamics with ") 375 disp("double-integrator model of aircraft roll dynamics with ")
376 disp("input \"aileron angle\" and output \"theta\". A ") 376 disp("input \"aileron angle\" and output \"theta\". A ")
377 disp("system for this model is generated by the command") 377 disp("system for this model is generated by the command")
378 cmd = "aircraft=zp2sys([],[0, 0],1,0,\"aileron angle\",\"theta\");"; run_cmd 378 cmd = "aircraft=zp([],[0, 0],1,0,\"aileron angle\",\"theta\");"; run_cmd
379 disp("The sampling time parameter 0 indicates that the system") 379 disp("The sampling time parameter 0 indicates that the system")
380 disp("is continuous time. A positive sampling time indicates a") 380 disp("is continuous time. A positive sampling time indicates a")
381 disp("discrete-time system (or sampled data system).") 381 disp("discrete-time system (or sampled data system).")
382 cmd = "sysout(aircraft)"; 382 cmd = "sysout(aircraft)";
383 run_cmd 383 run_cmd
385 disp("These signal names are used in OCST plots and design functions."); 385 disp("These signal names are used in OCST plots and design functions.");
386 disp("(Run the frequency response demo to see an example of the use of "); 386 disp("(Run the frequency response demo to see an example of the use of ");
387 disp("signal names in plots.)") 387 disp("signal names in plots.)")
388 prompt 388 prompt
389 elseif(zpopt == 4) # help 389 elseif(zpopt == 4) # help
390 help zp2sys 390 help zp
391 prompt 391 prompt
392 elseif(zpopt == 6) # return to main menu 392 elseif(zpopt == 6) # return to main menu
393 formopt = 4; 393 formopt = 4;
394 endif 394 endif
395 endwhile 395 endwhile
396 endif 396 endif
397 endwhile 397 endwhile
398 elseif(syschoice == ch_extract) # extract system information 398 elseif(syschoice == ch_extract) # extract system information
399 disp("Extract information from a system data structure in a selected format:") 399 disp("Extract information from a system data structure in a selected format:")
400 disp("The actions of operations ss2sys, tf2sys, and zp2sys are reversed by") 400 disp("The actions of operations ss, tf, and zp are reversed by")
401 disp("respective functions sys2ss, sys2tf, and sys2zp. The latter two"); 401 disp("respective functions sys2ss, sys2tf, and sys2zp. The latter two");
402 disp("functions are applicable only to SISO systems.") 402 disp("functions are applicable only to SISO systems.")
403 formopt = 0; 403 formopt = 0;
404 while(formopt != 8) 404 while(formopt != 8)
405 formopt = menu("Extract system information", ... 405 formopt = menu("Extract system information", ...
417 help sys2tf 417 help sys2tf
418 elseif(formopt == 3) 418 elseif(formopt == 3)
419 help sys2zp 419 help sys2zp
420 elseif(formopt == 4) 420 elseif(formopt == 4)
421 help sysgetsignals 421 help sysgetsignals
422 cmd="sys=ss2sys(rand(4),rand(4,2),rand(3,4));"; 422 cmd="sys=ss(rand(4),rand(4,2),rand(3,4));";
423 run_cmd 423 run_cmd
424 printf("Example: All signals names can be extracted by\n"); 424 printf("Example: All signals names can be extracted by\n");
425 cmd = "[Ast,Ain,Aout,Ayd] = sysgetsignals(sys)"; 425 cmd = "[Ast,Ain,Aout,Ayd] = sysgetsignals(sys)";
426 run_cmd 426 run_cmd
427 printf("Example: Input signal names can be extracted as\n"); 427 printf("Example: Input signal names can be extracted as\n");
428 cmd = "Ain = sysgetsignals(sys,\"in\")"; 428 cmd = "Ain = sysgetsignals(sys,\"in\")";
429 run_cmd 429 run_cmd
430 printf("Example: The name of output signal 2 can be extracted as\n"); 430 printf("Example: The name of output signal 2 can be extracted as\n");
431 cmd = "Aout = sysgetsignals(sys,\"out\",2)"; 431 cmd = "Aout = sysgetsignals(sys,\"out\",2)";
432 run_cmd 432 run_cmd
433 printf("\nNotice that Aout is returned as a list; the signal name\n"); 433 printf("\nNotice that Aout is returned as a cell array; the signal name\n");
434 printf("itself is obtained by specifying the input parameter strflg\n"); 434 printf("itself is obtained by specifying the input parameter strflg\n");
435 cmd = "Aout = sysgetsignals(sys,\"out\",2,1)"; 435 cmd = "Aout = sysgetsignals(sys,\"out\",2,1)";
436 run_cmd 436 run_cmd
437 prompt 437 prompt
438 cmd = "help syssetsignals"; 438 cmd = "help syssetsignals";
452 prompt 452 prompt
453 endwhile 453 endwhile
454 elseif(syschoice== ch_update) 454 elseif(syschoice== ch_update)
455 disp("The OCST system data structure format will store a system in the same format") 455 disp("The OCST system data structure format will store a system in the same format")
456 disp("as that with which it was initialized. For example, consider the following:") 456 disp("as that with which it was initialized. For example, consider the following:")
457 cmd = "sys=zp2sys([1, 2],[3, 4, 5],6)"; 457 cmd = "sys=zp([1, 2],[3, 4, 5],6)";
458 run_cmd 458 run_cmd
459 disp(" ") 459 disp(" ")
460 disp("Notice the internal variables in the structure include zer, pol, and k,") 460 disp("Notice the internal variables in the structure include zer, pol, and k,")
461 disp("the required variables for zero-pole form. We can update the system") 461 disp("the required variables for zero-pole form. We can update the system")
462 disp("to include state-space form as follows:") 462 disp("to include state-space form as follows:")
470 help sysupdate 470 help sysupdate
471 prompt 471 prompt
472 elseif(syschoice == ch_view) 472 elseif(syschoice == ch_view)
473 disp("The sysout command can be used to view a system in any desired format.") 473 disp("The sysout command can be used to view a system in any desired format.")
474 disp("For example, consider the system created as follows:") 474 disp("For example, consider the system created as follows:")
475 cmd = "aircraft=zp2sys(1,[0, 0],1,0,\"aileron angle\",\"theta\");"; run_cmd 475 cmd = "aircraft=zp(1,[0, 0],1,0,\"aileron angle\",\"theta\");"; run_cmd
476 disp("The system may be viewed in its default format (zero-pole) as follows") 476 disp("The system may be viewed in its default format (zero-pole) as follows")
477 cmd = "sysout(aircraft)"; 477 cmd = "sysout(aircraft)";
478 run_cmd 478 run_cmd
479 disp(" ") 479 disp(" ")
480 disp("The system may be viewed in state-space or transfer function form as well:") 480 disp("The system may be viewed in state-space or transfer function form as well:")