home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / moddemo.m < prev    next >
Text File  |  1999-04-29  |  8KB  |  201 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 moddemo()
  18. # Octave Controls toolbox demo: Model Manipulations demo
  19. # Written by David Clem August 15, 1994
  20.  
  21. # a s hodel: updated to reflect updated output order in ss2zp
  22.  
  23.   while (1)
  24.     clc
  25.     disp('Octave Model Manipulations Demo')
  26.     disp('=======================================')
  27.     disp('  1)  Perform continuous to discrete time conversion (c2d)')
  28.     disp('  2)  Convert from state space to zero / pole form (ss2zp)')
  29.     disp('      Convert from zero / pole to state space form (zp2ss)')
  30.     disp('  3)  Convert from state space to transfer function form (ss2tf)')
  31.     disp('      Convert from transfer function to state space form (tf2ss)')
  32.     disp('  4)  Convert from transfer function to zero / pole form (tf2zp)')
  33.     disp('      Convert from zero / pole to transfer function form (zp2tf)')
  34.     disp('  5)  Return to main demo menu')
  35.     disp(' ')
  36.     k=6;
  37.     while(k > 5 || k < 1)
  38.       k = input('Please enter a number:');
  39.     endwhile
  40.     if (k == 1)
  41.       clc
  42.       disp('Perform continuous to discrete time conversion (c2d)\n')
  43.       disp('Example #1, Consider the following continuous time state space system:\n')
  44.       a=[0 1;-25 -4]
  45.       b=[0;1]
  46.       c=[1 1]
  47.       d=1
  48.       prompt
  49.       disp('\nTo convert this to a discrete time system (using a zero order hold),')
  50.       disp('use the following commands:\n')
  51.       cmd="sys=ss2sys(a,b,c,d);";
  52.       run_cmd
  53.       cmd="dsys = c2d(sys,0.2);";
  54.       run_cmd
  55.       cmd="sysout(dsys);";
  56.       run_cmd
  57.       disp('Function check\n')
  58.       disp('Check the poles of sys vs dsys:\n')
  59.       cmd="[da,db]=sys2ss(dsys);";
  60.       run_cmd
  61.       cmd="lam = eig(a);";
  62.       run_cmd
  63.       disp('Discretize the continuous time eigenvalues using the matrix exponential:\n')
  64.       disp('lambc = exp(lam*0.2)\n')
  65.       lambc = exp(lam*0.2)
  66.       disp('Check the eigenvalues of da\n')
  67.       lambd = eig(da)
  68.       disp('Calculate the difference between lambd and lambc:\n')
  69.       cmd = 'error = sort(lambd)-sort(lambc)\n';
  70.       run_cmd
  71.       disp("The error is on the order of roundoff noise, so we're o.k.")
  72.       prompt
  73.       clc
  74.     elseif (k == 2)
  75.       clc
  76.       disp('Convert from state space to zero / pole form (ss2zp)\n')
  77.       disp('Example #1, Consider the following state space system:\n')
  78.       a=[0 3 1;-2 -4 5;5 8 2]
  79.       b=[0;5;2.5]
  80.       c=[6 -1.9 2]
  81.       d=[-20]
  82.       prompt
  83.       disp(' ')
  84.       disp('\nTo find the poles and zeros of this sytstem, use the following command:\n')
  85.       disp('\n[zer, pol] = ss2zp(a, b, c, d)\n')
  86.       prompt
  87.       disp('Results:\n')
  88.       [zer, pol] = ss2zp(a, b, c, d)
  89.       disp('Variable Description:\n')
  90.       disp('zer, pol => zeros and poles of the state space system')
  91.       disp('a, b, c, d => state space system\n')
  92.       prompt
  93.       clc
  94.       disp('Convert from zero / pole to state space form (zp2ss)\n')
  95.       disp('Example #1, Consider the following set of zeros and poles:\n')
  96.       zer
  97.       pol
  98.       prompt
  99.       disp('\nTo find an equivalent state space representation for this set of poles')
  100.       disp('and zeros, use the following commands:\n')
  101.       k=1
  102.       disp('\n[na, nb, nc, nd] = zp2ss(zer, pol, k)\n')
  103.       prompt
  104.       disp('Results:\n')
  105.       [na, nb, nc, nd] = zp2ss(zer, pol, k)
  106.       disp('Variable Description:\n')
  107.       disp('na, nb, nc, nd => state space system equivalent to zero / pole input')
  108.       disp('zer, pol => zeros and poles of desired state space system')
  109.       disp('k => gain associated with the zeros\n')
  110.       prompt
  111.       disp('Function check\n')
  112.       disp('Are the eigenvalues of the origonal state space system the same as the')
  113.       disp('eigenvalues of the newly constructed state space system ?\n')
  114.       disp('Find the difference between the two sets of eigenvalues')
  115.       disp('error = sort(eig(a)) - sort(eig(na))\n')
  116.       error = sort(eig(a)) - sort(eig(na))
  117.       prompt
  118.       clc
  119.     elseif (k == 3)
  120.       clc
  121.       disp('Convert from state space to transfer function (ss2tf)\n')
  122.       disp('Example #1, Consider the following state space system:\n')
  123.       a=[0 1;-2 -3]
  124.       b=[1;1]
  125.       c=[1 9]
  126.       d=[1]
  127.       prompt
  128.       disp('\nTo find an equivalent transfer function for this system, use')
  129.       disp('the following command:\n')
  130.       disp('[num, den] = ss2tf(a, b, c, d)\n')
  131.       prompt
  132.       disp('Results:\n')
  133.       [num,den] = ss2tf(a, b, c, d)
  134.       disp('Variable Description:\n')
  135.       disp('num, den => numerator and denominator of transfer function that is')
  136.       disp('            equivalent to the state space system')
  137.       disp('a, b, c, d => state space system\n')
  138.       prompt
  139.       clc
  140.       disp('Convert from transfer function to state space form (tf2ss)\n')
  141.       disp('Example #1, Consider the following transfer function:\n')
  142.       num
  143.       den
  144.       prompt
  145.       disp('\nTo find an equivalent state space representation for this system, use')
  146.       disp('the following command:\n')
  147.       disp('[a, b, c, d] = tf2ss(num, den)\n')
  148.       prompt
  149.       disp('Results:\n')
  150.       [a, b, c, d] = tf2ss(num, den)
  151.       disp('Variable Description:\n')
  152.       disp('a, b, c, d => state space system equivalent to transfer function input')
  153.       disp('num, den => numerator and denominator of transfer function that is equivalent')
  154.       disp('            to the state space system\n')
  155.       prompt
  156.       clc
  157.     elseif (k == 4)
  158.       clc
  159.       disp('Convert from transfer function to zero / pole form (tf2zp)\n')
  160.       disp('Example #1, Consider the following transfer function:\n')
  161.       num=[1 2 3 4 5 ]
  162.       den=[1 2 3 4 5 6 7]
  163.       prompt
  164.       disp('\nTo find the zeros and poles of this system, use the following command:\n')
  165.       disp('[zer,pol] = tf2zp(num,den)\n')
  166.       prompt
  167.       disp('Results:\n')
  168.       [zer,pol] = tf2zp(num,den)
  169.       disp('Variable Description:\n')
  170.       disp('zer,pol => zeros and poles of the transfer function')
  171.       disp('num, den => numerator and denominator of transfer function\n')
  172.       prompt
  173.       clc
  174.       disp('Convert from zero / pole to transfer function (zp2tf)\n')
  175.       disp('Example #1, Consider the following set of zeros and poles:\n')
  176.       zer
  177.       pol 
  178.       prompt
  179.       disp('\nTo find an equivalent transfer function representation for this set')
  180.       disp('of poles and zeros, use the following commands:\n')
  181.       k=1
  182.       disp('\n[num, den] = zp2tf(zer, pol, k)\n')
  183.       prompt
  184.       disp('Results:\n')
  185.       [num, den] = zp2tf(zer, pol, k)
  186.       disp('Variable Description:\n')
  187.       disp('[num, den] => transfer function representation of desired set of zeros')
  188.       disp('              and poles') 
  189.       disp('a, b, c, d => state space system')
  190.       disp('zer, pol => zeros and poles of desired state space system')
  191.       disp('k => gain associated with the zeros\n')
  192.       prompt
  193.       clc
  194.     elseif (k == 5)
  195.       return
  196.     endif
  197.   endwhile  
  198. endfunction
  199.