home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / rldemo.m < prev    next >
Text File  |  1999-04-29  |  10KB  |  297 lines

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