home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / bddemo.m < prev    next >
Text File  |  1999-03-05  |  24KB  |  614 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 bddemo()
  18. # Octave Controls toolbox demo: Block Diagram Manipulations demo
  19. # Written by David Clem August 15, 1994
  20. # Modified by A S Hodel Summer-Fall 1996
  21.  
  22.   str_sav = implicit_str_to_num_ok;
  23.   sav_page = page_screen_output;
  24.   implicit_str_to_num_ok = 1;
  25.   page_screen_output = 1;
  26.  
  27.   while (1)
  28.     clc
  29.     k=0;
  30.     while(k > 14 || k < 1)
  31.       k = menu("Octave Block Diagram Manipulations Demo", ...
  32.       "sysadd/syssub: F(s) = G(s) +/- H(s)", ...
  33.      "sysappend: add new inputs/outputs", ...
  34.     "syssetsignals: change names of inputs, outputs, and/or states", ...
  35.     "sysconnect: connect specified system inputs/outputs", ...
  36.     "syscont/sysdisc: extract the continuous (discrete) part of a system", ...
  37.     "sysdup: duplicate specified inputs/outputs", ...
  38.     "sysgroup: group two systems into a single system,", ...
  39.     "sysmult: F(s) = G(s)*H(s) (series connection)", ...
  40.     "sysprune: keep only specified inputs/outputs", ...
  41.     "sysscale: scale inputs/outputs by specified gain matrices", ...
  42.     "parallel: parallel connection of two systems", ...
  43.     "buildssic: the combination of all", ...
  44.     "Design examples:", ...
  45.     "Return to main demo menu");
  46.     endwhile
  47.     if (k == 1)
  48.       clc
  49.       disp("sysadd: add two systems together")
  50.       disp("syssub: subtract F = G - H")
  51.       prompt
  52.       help sysadd
  53.       prompt
  54.       help syssub
  55.       prompt
  56.       disp('Example #1, \n')
  57.       cmd = "sys1 = tf2sys([1 -1],[1 2 1]);";
  58.       run_cmd
  59.       cmd = "sys2 = tf2sys([1 -1],[1 2 3]);";
  60.       run_cmd
  61.       disp("sys1=")
  62.       sysout(sys1);
  63.       prompt
  64.       disp("sys2=")
  65.       sysout(sys2);
  66.       cmd = "sys_sum1 = sysadd(sys1,sys1);";
  67.       run_cmd
  68.       disp("This example adds sys1 to itself.")
  69.       cmd = "sysout(sys_sum1)";
  70.       run_cmd
  71.       disp("Notice that the numerator is twice what it used to be.")
  72.       prompt
  73.       disp("Example 2:")
  74.       cmd = "sys_sub1 = syssub(sys1,sys2);";
  75.       run_cmd
  76.       disp("Notice that sysadd (actually sysgroup, called by sysadd) lets you")
  77.       disp("know that your two systems had identical names for their states,")
  78.       disp("inputs and outputs.  The warning message is perfectly harmless,")
  79.       disp("and is provided for user information only.")
  80.       disp("sys_sub1=")
  81.       sysout(sys_sub1)
  82.       disp("Notice that, since the two transfer functions had different")
  83.       disp("denominators, syssub converted the primary system type to ")
  84.       disp("state space.  This is the typical behavior unless the")
  85.       disp("the two systems are both SISO, they both have the same poles,")
  86.       disp("and at least one of them has  tf for its primary system type.");
  87.       prompt
  88.     elseif (k == 2)
  89.       disp("sysappend: add new inputs and/or outputs to a system")
  90.       help sysappend
  91.       prompt
  92.       disp("Consider a double-integrator system:")
  93.       sys = tf2sys(1,[1 0 0]);
  94.       sys=sysupdate(sys,"ss");
  95.       sysout(sys,"ss");
  96.       disp("We add a velocity disturbance input as follows:")
  97.       cmd = "sys1=sysappend(sys,[1;0]);";
  98.       run_cmd
  99.       sysout(sys1,"ss");
  100.       disp("Names of inputs can be included as follows:")
  101.       cmd = "sys1=sysappend(sys,[1;0], [],[],[],\"Disturb\");";
  102.       run_cmd
  103.       disp("Notice that empty matrices can be listed for the D matrix if")
  104.       disp("all entries are zeros.")
  105.       disp(" ")
  106.       disp("sys1 is thus:")
  107.       sysout(sys1);
  108.       prompt
  109.     elseif (k == 3)
  110.       disp("syssetsignals:")
  111.       help syssetsignals
  112.       disp("Example system");
  113.       a = rand(3,3);
  114.       b = rand(3,2);
  115.       c = rand(2,3);
  116.       sys = ss2sys(a,b,c);
  117.       sysout(sys);
  118.       prompt
  119.       disp("Change state names to larry, moe, and curly as follows:")
  120.       cmd = "sys = syssetsignals(sys,\"st\",list(\"larry\",\"moe  \" , \"curly\"));";
  121.       run_cmd
  122.       disp("Indicate that output 2 is discrete-time:")
  123.       cmd = "sys = syssetsignals(sys,\"yd\",1,2);";
  124.       run_cmd
  125.       disp("Change output 2 name to \"Vir\"");
  126.       cmd = "sys = syssetsignals(sys,\"out\",\"Vir\",2);";
  127.       run_cmd
  128.       disp("Resulting system is:")
  129.       sysout(sys);
  130.       prompt
  131.     elseif (k == 4)
  132.       help sysconnect
  133.       prompt
  134.       disp("********* N O T E *********")
  135.       disp("sysconnect is demonstrated fully in the design examples (option 13)");
  136.       prompt
  137.     elseif (k == 5)
  138.       disp("syscont and sysdisc: ")
  139.       disp("Example block diagram 1:")
  140.       disp("        ------------------     ---------------------");
  141.       disp(" u_in ->| Discrete system |--->| Continuous system | ---> y_out");
  142.       disp("        ------------------     ---------------------");
  143.       sys1 = tf2sys([1 2],[1 2 1], 1,"u_in","y_disc");
  144.       sys2 = tf2sys([1 0],[1 -3 -2],0,"c_in","y_out");
  145.       sys = sysmult(sys2,sys1);
  146.       disp("Consider the hybrid system")
  147.       sysout(sys);
  148.       prompt
  149.       help syscont
  150.       disp("The continuous part of the system can be extracted with syscont")
  151.       cmd = "[csys,Acd,Ccd] = syscont(sys);";
  152.       run_cmd
  153.       disp("The resulting csys is")
  154.       sysout(csys);
  155.       disp("Notice that B is 0; there is no purely continuous path from the")
  156.       disp("input to the output");
  157.       prompt
  158.       help sysdisc
  159.       disp("The discrete part of the system can be extracted with sysdisc")
  160.       cmd = "[dsys,Adc,Cdc] = sysdisc(sys)";
  161.       run_cmd
  162.       disp("The resulting dsys is")
  163.       sysout(dsys);
  164.       disp("sysdisc returns dsys=empty since sys has no discrete outputs.");
  165.       prompt
  166.       disp("Example block diagram 2:")
  167.       sys1 = tf2sys([1 2],[1 2 1], 1,"u_in","y_disc");
  168.       sys2 = tf2sys([1 0],[1 -3 -2],0,"c_in","y_out");
  169.       disp("             ---------------------")
  170.       disp(" u_in -->o-->| Discrete system   | --------> y_disc")
  171.       disp("         ^   ---------------------    |")  
  172.       disp("         |                            | ");
  173.       disp("         -----------------------------|---")
  174.       disp("                                      |  |")
  175.       disp("         ------------------------------  |")
  176.       disp("         |                               |")
  177.       disp("         v   ---------------------       |")
  178.       disp(" c_in -->o-->| continuous system | --------> y_out")
  179.       disp("             ---------------------")
  180.       disp("repeat the above example with sys=")
  181.       sys = sysgroup(sys1, sys2);
  182.       sysout(sys)
  183.       prompt
  184.       sys = sysconnect(sys,[1 2],[2 1]);
  185.       sysout(sys);
  186.       cmd = "[csys,Acd,Bcd] = syscont(sys);";
  187.       run_cmd
  188.       cmd = "[dsys,Acd,Bcd] = sysdisc(sys);";
  189.       run_cmd
  190.       disp("csys is now")
  191.       sysout(csys)
  192.       disp("dsys is now")
  193.       sysout(dsys);
  194.       prompt
  195.     elseif (k == 6)
  196.       help sysdup
  197.       prompt
  198.       disp("********* N O T E *********")
  199.       disp("sysdup is fully demonstrated in the design examples (option 13)")
  200.       prompt
  201.     elseif (k == 7)
  202.       help sysgroup
  203.       disp(" ")
  204.       prompt
  205.       disp("Example: combine two SISO systems together:")
  206.       cmd = "sys_a=tf2sys([1 2],[3 4]);";
  207.       run_cmd
  208.       cmd = "sys_b=tf2sys([5 6],[7 8],1);";
  209.       run_cmd
  210.       cmd = "sys_g=sysgroup(sys_a,sys_b);";
  211.       run_cmd
  212.       disp("Notice that sysgroup warns you when you join a purely continuous")
  213.       disp("system to a purely discrete system.  sysgroup also warns when")
  214.       disp("you join two systems that have common state, input, or output names.")
  215.       cmd = "sysout(sys_g)";
  216.       run_cmd
  217.       disp("Since the grouped system is a multiple-input multiple-output system,")
  218.       disp("the output system is by default in state-space format.")
  219.       disp(" ")
  220.       disp("********* N O T E *********")
  221.       disp("sysgroup is further demonstrated in the design examples (option 13)")
  222.       prompt
  223.     elseif (k == 8)
  224.       help sysmult
  225.       disp("sysmult performs a series connection of two systems.")
  226.       disp("Example 1")
  227.       disp(" ")
  228.       disp("         ----------     ----------")
  229.       disp("   u --->|  Bsys  |---->|  Asys  |---> y")
  230.       disp("         ----------     ----------")
  231.       disp(" ")
  232.       Asys = tf2sys(1,[1 2 1],0,"a_in","a_out");
  233.       Bsys = tf2sys([2 3],[1 3 2],0,"b_in","b_out");
  234.       disp("Asys=")
  235.       sysout(Asys);
  236.       disp("Bsys=");
  237.       sysout(Bsys);
  238.       cmd = "sys = sysmult(Asys,Bsys);";
  239.       run_cmd
  240.       disp("sys =")
  241.       sysout(sys);
  242.       disp("Notice that sysmult automatically transforms to state space")
  243.       disp("internal representation.  This is to avoid numerical problems")
  244.       disp("when multiplying polynomials");
  245.       prompt
  246.       disp("Example 2: same system, except that Bsys is discrete-time");
  247.       Bsys = tf2sys([2 3],[1 3 2],1e-2,"b_in","b_out");
  248.       sysout(Bsys);
  249.       cmd = "sys = sysmult(Asys,Bsys);";
  250.       run_cmd
  251.       disp("sys =")
  252.       sysout(sys);
  253.       prompt
  254.     elseif (k == 9)
  255.       help sysprune
  256.       prompt
  257.       disp("********* N O T E *********")
  258.       disp("sysprune is demonstrated in the design examples (option 13)");
  259.       prompt
  260.     elseif (k == 10)
  261.       help sysscale
  262.       disp(" ")
  263.       prompt
  264.       disp("********* N O T E *********")
  265.       disp("See the design examples (option 13) for use of sysscale.")
  266.       prompt
  267.     elseif ( k == 11)
  268.       help parallel
  269.       disp("parallel operates by making a call to sysgroup and sysscale.")
  270.       disp("Example:")
  271.       sys1 = tf2sys(1,[1 1],0,"in1","out1");
  272.       sys2 = tf2sys(2,[1 2],0,"in2","out2");
  273.       disp("sys1=")
  274.       sysout(sys1);
  275.       disp("sys2=")
  276.       sysout(sys2);
  277.       cmd = "sysp = parallel(sys1,sys2);";
  278.       run_cmd
  279.       disp("sysp=")
  280.       sysout(sysp);
  281.       prompt
  282.       disp("parallel can be used for multiple input systems as well:")
  283.  
  284.       in1 = list("u1.1","u1.2");
  285.       in2 = list("u2.1","u2.2");
  286.       out1 = list("y1.1","y1.2");
  287.       out2 = list("y2.1","y2.2");
  288.  
  289.       sys1 = ss2sys([-1,0;0 -2],eye(2),eye(2),[]);
  290.       sys2 = ss2sys([-2,0;0 -4],eye(2),eye(2),[]);
  291.  
  292.       sys1 = syssetsignals(sys1,"in",in1);
  293.       sys1 = syssetsignals(sys1,"out",out1);
  294.  
  295.       sys2 = syssetsignals(sys2,"in",in2);
  296.       sys2 = syssetsignals(sys2,"out",out2);
  297.      
  298.       disp("sys1=")
  299.       sysout(sys1);
  300.       disp("sys2=")
  301.       sysout(sys2);
  302.       cmd = "sysp = parallel(sys1,sys2);";
  303.       run_cmd
  304.       disp("sysp=")
  305.       sysout(sysp);
  306.       prompt
  307.     elseif (k == 12)
  308.       # buildssic description
  309.       disp(" ")
  310.       disp("        ---------------------------------------")
  311.       disp("                    b u i l d s s i c")
  312.       disp("          (BUILD State Space InterConnections)")
  313.       disp("        ---------------------------------------")
  314.       disp(" ")
  315.       disp("buildssic builds a single system from up to 8 systems.")
  316.       disp("It's primary pupose is the forming of interconnections")
  317.       disp("for H2/H_inf designs and the building of closed loop")
  318.       disp("systems.")
  319.       disp("The interconnections may be of arbitrary complexity.")
  320.       disp("The use of buildssic is an alternative to sysgroup,")
  321.       disp("sysadd/syssub, sysappend, sysconnect, sysdup, sysmult")
  322.       disp("sysprune, sysscale, parallel etc.")
  323.       disp("In contrast to these functions buildssic does not")
  324.       disp("handle mixed continuous and discrete systems. However,")
  325.       disp("discrete systems can be connected as long as their")
  326.       disp("sampling times are identical. Another drawback: the")
  327.       disp("names of input/output and state variables are clobbered.")
  328.       disp("Of course, buildsysic is useful in combination with sysgroup,")
  329.       disp("sysmult etc.")
  330.       prompt
  331.       disp("********* N O T E *********")
  332.       disp("buildssic is demonstrated in the design examples (option 13)");
  333.       prompt
  334.     elseif (k == 13)
  335.       disp("Design examples")
  336.       disp("Packed system matrices may be connected and manipulated")
  337.       disp("With the functions listed below:")
  338.       disp("  sysdup: duplicate selected inputs/outputs")
  339.       disp("  sysconnect: connect selected inputs/outputs")
  340.       disp("  sysgroup: group two systems together")
  341.       disp("  sysprune: prune a system to keep only selected inputs and outputs")
  342.       disp("  sysscale:pre/post multiply a system by constant matrices")
  343.       disp("  buildssic: connect systems with arbitrary complexity.")
  344.       prompt
  345.       disp("As a simple example, we will construct the system block ")
  346.       disp("diagram shown below ")
  347.       disp(" ")
  348.       disp("         +          --------    --------");
  349.       disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  350.       disp("            -^      --------    --------  |");
  351.       disp("             |                            |");
  352.       disp("             ------------------------------");
  353.       disp(" ")
  354.       disp("where P(s) is the plant, K(s) is the controller.")
  355.       prompt
  356.       disp("Simple example: P(s) is a first order lag, K(s) is a PI ")
  357.       disp("controller")
  358.       nump = 1;
  359.       denp = [1  1];
  360.       disp("P(s)=")
  361.       tfout(nump,denp)
  362.       numk = [1 1];
  363.       denk = [1 0];
  364.       disp("\nK(s)=")
  365.       tfout(numk,denk);
  366.       prompt
  367.       disp("We'll show three approaches.  ")
  368.       P = tf2sys(nump,denp,0,"plant input","plant output");
  369.       K = tf2sys(numk, denk,0,"controller input","controller output");
  370.  
  371.       meth = 0;
  372.       while(meth != 5)
  373.         disp("The first method consists of the following steps:")
  374.         disp("   step 1: create systems P and K")
  375.         disp("   step 2: group P and K together")
  376.         disp("   step 3: create a summing junction")
  377.         disp("   step 4: connect outputs to respective inputs")
  378.         disp("   step 5: prune the desired i/o connections")
  379.         disp("The second method is done as follows:")
  380.         disp("   step 1: create systems P and K and a summing block S")
  381.         disp("   step 2: connect P, K, and S in series")
  382.         disp("   step 3: connect y to inverted summing connection")
  383.         disp("   step 4: prune the desired i/o connections")
  384.         disp("The third method uses buildssic:")
  385.         disp("   step 1: GW = buildssic(...,K,P)")
  386.         disp(" ")
  387.         disp("Other design examples are in dgkfdemo (controldemo option 7)")
  388.         disp(" ")
  389.         meth = menu("Select design example method", ...
  390.         "Method 1 ", ...
  391.         "Method 1 (w/o algebraic loop warning)", ...
  392.         "Method 2", ...
  393.         "Method 3", ...
  394.         "Exit design examples");
  395.         if(meth == 1)
  396.           disp(" * * * Method 1 * * *")
  397.           disp(" ")
  398.           disp("         +          --------    --------");
  399.           disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  400.           disp("            -^      --------    --------  |");
  401.           disp("             |                            |");
  402.           disp("             ------------------------------");
  403.           disp(" ")
  404.           disp("Step 1: put plants in system format:");
  405.           nump
  406.           denp
  407.           cmd =  "P = tf2sys(nump,denp,0,""plant input"",""plant output"");";
  408.           run_cmd
  409.           disp("P=")
  410.           sysout(P)
  411.           prompt
  412.           numk
  413.           denk
  414.           cmd = "K = tf2sys(numk, denk,0,""controller input"",""controller output"");";
  415.           run_cmd
  416.           sysout(K)
  417.           prompt
  418.           disp("Step 2: group the systems together")
  419.           cmd = "PK = sysgroup(P,K);";
  420.           run_cmd
  421.           disp("PK=")
  422.           sysout(PK);
  423.           prompt
  424.           disp(" ")
  425.           disp("                           y2   u1")
  426.           disp("         +          --------    --------");
  427.           disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  428.           disp("  u2        -^      --------    --------    |  y1");
  429.           disp("          u3 |                              |");
  430.           disp("             --------------------------------");
  431.           disp(" ")
  432.           disp("The controller has two inputs summed together, r(t)")
  433.           disp("and the negative feedback of  y(t)")
  434.           disp("Step 3a: duplicate controller input: (input 2 of PK)")
  435.           prompt
  436.           cmd = "PK = sysdup(PK,[],2);";
  437.           run_cmd
  438.           disp("PK=")
  439.           sysout(PK);
  440.           disp("Notice that PK now has three inputs (input 3 is a duplicate ");
  441.           prompt("of input 2).  Press return to go on")
  442.           disp("Step 3b: scale input 3 by -1")
  443.           cmd = "PK = sysscale(PK,[],diag([1,1,-1]));";
  444.           run_cmd
  445.           disp("PK=")
  446.           sysout(PK);
  447.           prompt
  448.           disp("Step 4: connect:")
  449.           disp("   y(t) (output 1) to the negative sum junction (input 3)")
  450.           disp("   u(t) (output 2) to plant input (input 1)")
  451.           disp("and prune extraneous inputs/outputs (retain input 2, output 1)")
  452.           prompt
  453.           out_connect = [1 2]
  454.           in_connect = [3 1]
  455.           cmd = "PK0 = sysconnect(PK,out_connect,in_connect);"; 
  456.           run_cmd
  457.           prompt
  458.           disp("Notice that sysconnect detects the possibility of algebraic") 
  459.           disp("connections when connecting inputs.  Option 2 (Method 1 ")
  460.           disp("without algebraic loops) shows how to avoid this warning")
  461.           disp("by performing connections one at a time.")
  462.           prompt
  463.           disp("PK0=")
  464.           sysout(PK0);
  465.           disp("Notice that the connected inputs now have stars on their")
  466.           disp("names.  This is how the Octave controls toolbox reminds you")
  467.           disp("that the loop has been closed around these inputs.")
  468.           prompt("Press return to prune extra inputs/outputs from system")
  469.           disp("Only keep plant output (output 1) and r(t) (input 2)")
  470.           cmd = "PK0 = sysprune(PK0,1,2);";
  471.           run_cmd
  472.           disp("PK0=")
  473.           sysout(PK0);
  474.           prompt
  475.           disp("The resulting closed-loop transfer function is obtained as follows:")
  476.           cmd = "[num,den] = sys2tf(PK0);";
  477.           run_cmd
  478.           prompt
  479.           disp("Transfer function is now")
  480.           tfout(num,den)
  481.           disp("You can check this: Pk0=PK/(1+PK), as expected")
  482.           prompt
  483.         elseif(meth == 2)
  484.           disp("Method 1 without algebraic loops")
  485.           disp(" ")
  486.           disp("                           y2   u1")
  487.           disp("         +          --------    --------");
  488.           disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  489.           disp("  u2        -^      --------    --------    |  y1");
  490.           disp("          u3 |                              |");
  491.           disp("             --------------------------------");
  492.           disp(" ")
  493.           disp("Recall that sysconnect checks for algebraic loops.  Although")
  494.           disp("Design option 1 gets a warning message about a possible");
  495.        disp("algebraic loop, such a loop does not exist.")
  496.           disp("This can be seen by performing the connections one at a time");
  497.           cmd = "PK = sysgroup(P,K);";
  498.           run_cmd
  499.           disp("PK=")
  500.           sysout(PK);
  501.           disp("Create an additial inverted input to the controller.")
  502.           cmd = "PK = sysdup(PK,[],2);";
  503.           run_cmd
  504.           cmd = "PK = sysscale(PK,[],diag([1,1,-1]));";
  505.           run_cmd
  506.           disp("PK=")
  507.           sysout(PK);
  508.           disp("Connect controller to plant:")
  509.           cmd = "PK0 = sysconnect(PK,2,1);"; 
  510.           run_cmd
  511.           disp("Plant output to negative control input")
  512.           cmd = "PK0 = sysconnect(PK0,1,3);"; 
  513.           run_cmd
  514.           disp("Only keep plant output (output 1) and r(t) (input 2)")
  515.           cmd = "PK0 = sysprune(PK0,1,2);";
  516.           run_cmd
  517.           disp("PK0=")
  518.           sysout(PK0);
  519.           prompt
  520.           disp("The transfer function form of PK0 is:")
  521.           sysout(PK0,"tf");
  522.           prompt
  523.         elseif(meth == 3)
  524.           disp(" * * * Method 2 * * *")
  525.           disp(" ")
  526.           disp("         +          --------    --------");
  527.           disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  528.           disp("            -^      --------    --------  |");
  529.           disp("             |                            |");
  530.           disp("             ------------------------------");
  531.           disp(" ")
  532.       disp("Step 1: We've already created systems P and K.  Create a sum ")
  533.       disp("block as follows:")
  534.       implicit_str_to_num_ok = "warn";
  535.       cmd = "S = ss2sys([],[],[],[1 -1],0,0,0,[],list(""r(t)"",""y(t)""),""e(t)"");";
  536.       run_cmd
  537.       implicit_str_to_num_ok = 1;
  538.       disp("You may avoid the string conversion warning by setting the ")
  539.       disp("Octave global variables implicit_str_to_num_ok = 1");
  540.       disp(" ");
  541.       disp("(You may wish to look at help ss2sys to see what the above does)");
  542.       disp("S=")
  543.       sysout(S)
  544.       disp("notice that this is just a gain block that outputs e = r - y")
  545.       prompt
  546.       disp("Step 2: series connections of P, K, and S")
  547.       cmd = "PKS = sysmult(P,sysmult(K,S));";
  548.       run_cmd
  549.       disp("PKS=")
  550.       sysout(PKS)
  551.       disp("Step 3: connect y to inverted input")
  552.       cmd = "PKcl = sysconnect(PKS,1,2);";
  553.       run_cmd
  554.       disp("PKcl=")
  555.       sysout(PKcl)
  556.       disp("Step 4: prune desired inputs/outputs")
  557.       cmd = "PKcl=sysprune(PKcl,1,1);";
  558.       run_cmd
  559.       disp("PKcl=")
  560.       sysout(PKcl)
  561.       prompt
  562.         elseif(meth == 4)
  563.           disp(" * * * Method 3 * * *")
  564.           disp(" ")
  565.           disp("         +          --------    --------");
  566.           disp("  r(t) ---> (+) --->| K(s) |--->| P(s) | ----> y(t)");
  567.           disp("            -^      --------    --------  |");
  568.           disp("             |                            |");
  569.           disp("             ------------------------------");
  570.           disp(" ")
  571.       disp("Step 1: We've already created systems P and K.")
  572.       disp("        Let us call buildssic:")
  573.       disp("   PKcl = buildssic([1 2;2 -1],[],[1],[2],P,K)")
  574.       disp(" ")
  575.       disp("                         ^      ^  ^   ^  ^ ^")
  576.       disp("                         |      |  |   |  | |")
  577.       disp("     Connection list ----+      |  |   |  | |")
  578.       disp(" internal input list -----------+  |   |  | +-- controller")
  579.       disp("         output list --------------+   |  |")
  580.       disp("          input list ------------------+  +---- plant")
  581.       disp(" ")
  582.       disp(" Connection list: connect input 1 (P) with output 2 (K)")
  583.       disp("                  connect input 2 (K) with neg. outp. 1 (P)")
  584.       disp(" ")
  585.       disp("  int. inp. list: do not append internal inputs")
  586.       disp("                  (e.g. the internal input of K (r-y))")
  587.       disp(" ")
  588.       disp("     output list: the only output is 1 (P), positive")
  589.       disp(" ")
  590.       disp("      input list: the only input is 2 (K), positive")
  591.       disp(" ")
  592.       cmd = "PKcl = buildssic([1 2;2 -1],[],[1],[2],P,K);"
  593.       run_cmd
  594.       sysout(PKcl)
  595.       prompt
  596.       disp("The transfer function form of PKcl is:")
  597.       sysout(PKcl,"tf");
  598.       disp("You can check this: PKcl = PK / (1 + PK), as expected")
  599.       prompt
  600.       elseif(meth != 5)
  601.         disp("Illegal selection")
  602.      endif
  603.     endwhile
  604.       
  605.     elseif (k == 14)
  606.       return
  607.     endif
  608.   endwhile  
  609.   implict_str_to_num_ok = str_sav;
  610.   page_screen_output = sav_page;
  611. endfunction
  612.