home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / CTRLDEMO.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.0 KB  |  79 lines

  1. echo on
  2. clc
  3. echo off
  4. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  5. echo on
  6. %    This demo shows the use of some of the control system design
  7. %    and analysis tools available in MATLAB.
  8. %
  9. pause % Strike any key to continue.
  10. clc
  11. %    Suppose we start with a plant description in transfer function
  12. %    form:                 2
  13. %                      .2 s  +  .3 s  +  1
  14. %           H(s)  =   -----------------------
  15. %                      2
  16. %                    (s  +  .4 s  +  1) (s + .5)
  17. %
  18. %    We enter the numerator and denominator coefficients separately
  19. %    into MATLAB:
  20.  
  21. num = [.2  .3  1];
  22. den1 = [1 .4 1];
  23. den2 = [1 .5];
  24.  
  25. pause % Strike any key to continue.
  26. clc
  27. %    The denominator polynomial is the product of the two terms. We
  28. %    use convolution to obtain the polynomial product:
  29.  
  30. den = conv(den1,den2)
  31. printsys(num,den)
  32.  
  33. pause % Strike any key to continue.
  34. clc
  35. %    We can look at the natural frequencies and damping factors of the
  36. %    plant poles:
  37.  
  38. damp(den)
  39.  
  40. %    A root-locus can be obtained by using RLOCUS
  41.  
  42. % Press any key to continue ...
  43.  
  44. rlocus(num,den); pause  % Press any key after plot ...
  45.  
  46. clc
  47. %    The plant may be converted to a state space representation
  48. %          .
  49. %          x = Ax + Bu
  50. %          y = Cx + Du
  51. %
  52. %    using the tf2ss command:
  53.  
  54. [a,b,c,d] = tf2ss(num,den)
  55. pause % Strike any key to continue.
  56. clc
  57. %    For systems described in state-space or by transfer functions,
  58. %    the step response is found by using the STEP command:
  59. step(a,b,c,d,1); title('Step response'), pause % Press any key after plot
  60.  
  61. clc
  62. %    The frequency response is found by using the BODE command:
  63.  
  64. bode(a,b,c,d,1); pause % Press any key after plot
  65. clc
  66. %    A linear quadratic regulator could be designed for this plant.
  67. %    For control and state penalties:
  68.  
  69. r = 1;
  70. [m,n] = size(a); 
  71. q = eye(m,n)
  72. %    the quadratic optimal gains, the associated Riccati solution,
  73. %    and the closed-loop eigenvalues are:
  74.  
  75. [k,s,e] = lqr(a,b,q,r)                  % Working, please wait...
  76. pause % Strike any key to end.
  77.  
  78. echo off
  79.