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

  1. %msdemo1
  2. echo on
  3. clc
  4. %   *************    DATA TYPES    **************
  5. %    A 1-output, 2-input, 2-state linear
  6. %    system is described by the following 
  7. %    four matrices
  8.  
  9. a=[ -.15 .5 ; -.5 -.15]
  10. pause % strike any key to continue
  11. clc
  12. b = [.2 4;-.4 0]
  13. pause % strike any key to continue
  14. c=[5 5]
  15. pause % strike any key to continue
  16. clc
  17. d=[ .1 -.1 ]
  18. pause % strike any key to continue
  19. clc
  20. %    The command
  21. %                PCK
  22. %    will pack this data into a system matrix 
  23. %    which we will call SYS
  24.  
  25. pause % strike any key to continue
  26.  
  27. sys = pck(a,b,c,d);
  28.  
  29.  
  30. %    Simply printing out the MATLAB matrix SYS 
  31. %    reveals the extra information embedded in
  32. %    this matrix
  33.  
  34. pause % strike any key to continue
  35. clc
  36. sys
  37. %    The matrix SYS is 4 by 5, and contains the
  38. %    state space matrices a, b, c, and d. these
  39. %    appear in the upper left, 3 by 4 corner of
  40. %    the matrix, arranged as [a b; c d]. the matrix
  41. %    SYS also has an extra row and column to indicate
  42. %    that it is a system matrix. The -INF in the
  43. %    (4,5) entry indicates system matrix, and the
  44. %    2 in the (1,5) entry indicates 2 STATES.
  45. pause % strike any key to continue
  46. clc
  47. %   The command
  48. %               MINFO,
  49. %   which stands for matrix_information, gives
  50. %   STATE, OUTPUT and INPUT information
  51.  
  52. pause; % strike any key to continue
  53.  
  54. minfo(sys)
  55.  
  56.  
  57. pause % strike any key to continue
  58. clc
  59. %    the command
  60. %               POLES
  61. %    will print the poles of this system
  62.  
  63. pause; % strike any key to continue
  64.  
  65. spoles(sys)
  66.  
  67.  
  68. pause % strike any key to continue
  69.  
  70. %    That gives an idea of the SYSTEM MATRIX
  71. %    data type. A VARYING MATRIX can be created
  72. %    by calculating a frequency response or time
  73. %    response of the system - first, a frequency
  74. %    response. Make a frequency vector of 4
  75. %    logarithmically spaced points from 0.1 to 1,
  76. %    using the MATLAB command LOGSPACE
  77.  
  78. pause; % strike any key to continue
  79.  
  80. omega = logspace(-1,0,4)
  81.  
  82.  
  83. pause; % strike any key to continue
  84. clc
  85.  
  86. %    The frequency response is computed with
  87. %    the command  FRSP. In particular
  88.  
  89. %       SYS_G = FRSP(SYS,OMEGA)
  90.  
  91. %    produces a VARYING matrix SYS_G, that is
  92. %    the frequency response of SYS at the four
  93. %    frequencies of OMEGA.
  94.  
  95. pause; % strike any key to continue
  96.  
  97. sys_g = frsp(sys,omega);
  98.  
  99.  
  100. pause; % strike any key to continue
  101. clc
  102.  
  103. %   If we print out the matrix SYS_G as a MATLAB
  104. %   matrix, we can see that the frequency information
  105. %   is embedded there
  106. pause; % strike any key to continue
  107. clc
  108. sys_g
  109. pause; % strike any key to continue
  110. %  SYS_G is a 5 by 3 matrix. the INF in the (5,3) entry
  111. %  implies VARYING matrix. the 4.00 in the (5,2) entry 
  112. %  indicates 4 data points are represented, and the first 4
  113. %  entries in the last (3rd) column are the frequencies.
  114. %  the 4 by 2 block in upper left corner are the frequency
  115. %  response matrices (each 1 by 2 - since SYS had 1 output
  116. %  and 2 inputs) stacked upon each other.
  117. pause; % strike any key to continue
  118. clc
  119.  
  120. %   run the matrix_information command MINFO
  121. %   on SYS_G to see that it is indeed a VARYING
  122. %   matrix.
  123.  
  124. pause; % strike any key to continue
  125.  
  126. minfo(sys_g)
  127.  
  128.  
  129. pause; % strike any key to continue
  130.  
  131. %   note that SYS_G is a VARYING MATRIX as
  132. %   expected. it consists of 4 points, and
  133. %   each matrix has 1 row and 2 columns. the
  134. %   command
  135. %           SEE
  136. %   is useful for displaying a varying matrix. it
  137. %   prints out the matrix at each independent
  138. %   variable value (here, interpreted as frequency)
  139.  
  140. pause; % strike any key to continue
  141.  
  142. see(sys_g)
  143.  
  144. pause; % strike any key to continue
  145. clc
  146.  
  147. %    in this case, the frequencies at which the
  148. %    frequency response has been computed are
  149. %    called the INDEPENDENT VARIABLES of sys_g.
  150. %    the command
  151. %                   SEEIV
  152. %    displays the independent variables of a
  153. %    of a varying matrix without showing all
  154. %    of the varying matrix data.
  155.  
  156. pause; % strike any key to continue
  157.  
  158. seeiv(sys_g)
  159.  
  160.  
  161. pause; % strike any key to continue
  162. clc
  163.  
  164. %    VARYING matrices can be plotted versus
  165. %    the independent variable with the command
  166. %    VPLOT, which stands for MATRIX PLOT. VPLOT
  167. %    plots each element of the varying matrix
  168. %    versus the independent variable. In this
  169. %    case, SYS_G has 1 row, and 2 columns, so
  170. %    the command
  171. %               VPLOT('liv,lm',SYS_G')
  172. %    plots a log-magnitude plot (lm means log-magnitude)
  173. %    of the 2 elements, with log axis for the
  174. %    independent variable (liv)
  175.  
  176. pause; % strike any key to continue
  177. echo off
  178. vplot('liv,lm',sys_g)
  179. xlabel('STRIKE ANY KEY TO CONTINUE')
  180. pause;
  181. echo on
  182. clc
  183.  
  184. %    VPLOT can also be used to plot Nyquist
  185. %    plots. let's calculate a much finer
  186. %    frequency response, over a larger range,
  187. %    100 points from 0.1 to 10.
  188.  
  189. pause; % strike any key to continue
  190.  
  191. omega = logspace(-1,1,100);
  192. sys_g = frsp(sys,omega);
  193.  
  194. pause; % strike any key to continue
  195. clc
  196. %
  197. %    check the frequencies with  SEEIV(SYS_G).
  198. %    it should be 100 points, from 0.1 to 10.
  199. %
  200. pause; % strike any key to continue
  201.  
  202. seeiv(sys_g)
  203.  
  204. pause; % strike any key to continue
  205. clc
  206.  
  207. %    now plot the 2 Nyquist plots of SYS_G with
  208. %
  209. %                 VPLOT('NYQ',SYS_G)
  210. %
  211. %    the 'NYQ' stands for REAL versus IMAGINARY, and
  212. %    the curves are parametrized by the independent
  213. %    variable
  214.  
  215. pause; % strike any key to continue
  216. echo off
  217. vplot('nyq',sys_g)
  218. xlabel('STRIKE ANY KEY TO CONTINUE')
  219. pause;
  220. echo on
  221. clc
  222.  
  223. %    portions of the varying matrix sys_g can
  224. %    be extracted out using XTRACT
  225.  
  226. %       XTRACT(SYS_G,0.4,2.1)
  227.  
  228. %    will extract from SYS_G those points with
  229. %    independent variable (frequency) values
  230. %    between 0.4 and 2.1
  231.     
  232. pause; % strike any key to continue
  233. clc
  234.  
  235. some = xtract(sys_g,0.4,2.1);
  236.  
  237. pause; % strike any key to continue
  238.  
  239. %   check that only a portion of the original
  240. %   independent variables are in SOME
  241. pause; % strike any key to continue
  242.  
  243. seeiv(some)
  244.  
  245. pause; % strike any key to continue
  246.  
  247. %    generate a Nyquist plot of some using
  248. %        VPLOT('NYQ',SOME)
  249.  
  250. pause; % strike any key to continue
  251. echo off
  252. vplot('nyq',some)
  253. xlabel('STRIKE ANY KEY TO CONTINUE')
  254. pause;
  255. echo on
  256. clc
  257.  
  258.  
  259. %     That is an introduction to generating frequency
  260. %     responses from system matrices, and plotting the
  261. %     results.
  262. %
  263. % Copyright MUSYN INC 1991,  All Rights Reserved
  264.