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

  1. echo off
  2. clear
  3. clg
  4. clc
  5. echo on
  6.  
  7.                            % SYSTEM DEMO %
  8.  
  9.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10.   %% This demo illustrates the use of the following functions         %%
  11.   %% from the Robust-Control Toolbox:                                 %%
  12.   %%                                                                  %%
  13.   %%                 TREE      MKSYS      BRANCH                      %%
  14.   %%                                                                  %%
  15.   %% These commands endow matlab with a special data structure called %%
  16.   %% a TREE which enables many matrices, along with their names and   %%
  17.   %% relationships to each other to be represented by a single TREE   %%
  18.   %% variable.  A SYSTEM is a special kind of tree.                   %%
  19.   %%------------------------------------------------------------------%%
  20.   %% Many matlab commands such as  SIGMA, H2LQG, and HINF make use of %%
  21.   %% the TREE and SYSTEM data structures to simplify user interaction %%
  22.   %% and reduce the amount of typing required to get a job done!      %%
  23.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24.  
  25. % R. Y. Chiang & M. G. Safonov 11/11/90
  26. % Copyright (c) 1988 by the MathWorks, Inc.
  27. % All Rights Reserved.
  28. % ----------------------------------------------------------------------
  29.  
  30. pause                % Press any key to continue
  31. clc
  32.                   %  LOAD SOME MATRICES %
  33.  
  34. % Lets load a few matrices and see what SYSTEM and TREE can do:
  35.  
  36. echo off
  37. hplant
  38. echo on
  39.  
  40. who
  41.  
  42. % The matrices [ag,bg,cg,dg] describe a standard state-space system,viz.,
  43. % the logitudinal dynamics of an aircraft.  The set of matrices
  44. % [A,B1,B2,C1,C2,D11,D12,D21,D22] also describe a two-port state-space
  45. % system, such as might be obtained by augmenting the aircraft in
  46. % preparation for HINF or H2LQG control design.
  47.  
  48. pause                % Press any key to continue
  49. clc
  50.                               % MKSYS %  
  51.  
  52. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  53. %%    The MKSYS command packs matrices describing a system into          %%
  54. %%    a single vector.                                                   %%
  55. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  56.  
  57. % For example,
  58.       ss_g = mksys(ag,bg,cg,dg);
  59.  
  60. % MKSYS also creates two-port systems:
  61.       TSS_ = mksys(A,B1,B2,C1,C2,D11,D12,D21,D22,'tss');
  62.  
  63.  
  64. % Other sorts of systems can be created too, e.g., descriptor systems ('des')
  65. % transfer function systems ('tf'), general polynomial system matrices 
  66. % ('gpsm'), etc.
  67.  
  68.  
  69.  
  70. pause                % Press any key to continue
  71. echo off
  72. clc
  73. help mksys
  74. pause                % Press any key to continue
  75. clc
  76. echo on
  77.  
  78.                             % BRANCH %
  79.    
  80. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  81. %%  The BRANCH function recovers matrices packed in a SYSTEM or     %%
  82. %%  other TREE vector.                                              %%
  83. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  84.  
  85. % Let's clear the matrices the matrices [ag,bg,cg,dg] and [A,B1,B2, ..
  86. % C1,C2,D11,D12,D21,D22] from the workspace so we can see how BRANCH
  87. % works.
  88.  
  89. clear ag bg cg dg A B1 B2 C1 C2 D11 D12 D21 D22
  90. who
  91.  
  92.  
  93. pause                % Press any key to continue
  94. clc
  95. % To recover the matrices D11 and C2 from the SYSTEM vector TSS_
  96. % we can type:
  97.  
  98.        [D11,C2] = branch(TSS_,'d11,c2')
  99.  
  100.  
  101. pause                % Press any key to continue
  102. echo off
  103. clc
  104. help branch
  105. echo on
  106.  
  107.  
  108.  
  109. pause                % Press any key to continue
  110. clc
  111.  
  112.  
  113.  
  114.  
  115. % To get the matrix ag from the state space system ss_g, we can type
  116.  
  117. ag=branch(ss_g,'a')
  118.  
  119.  
  120.  
  121. pause                % Press any key to continue
  122. clc
  123. % To recover all the matrices from ss_g at once one may type
  124.  
  125. [ag,bg,cg,dg]=branch(ss_g);
  126.  
  127. who
  128.  
  129. pause                % Press any key to continue
  130. clc
  131. echo on
  132.  
  133.                   % H2LGQ, HINF and SIGMA examples %
  134.  
  135. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  136. %% Now we will illustrate how the use of SYSTEM vectors saves typing %%
  137. %% when using system related functions like H2LGQ, HINF and SIGMA.   %%
  138. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  139.  
  140. % Let's do an H2LQG control design for the two-port system TSS_
  141. % and compute the resultant controller's singular value bode plot.
  142.  
  143. % One could do this by typing
  144. %      [af,bf,cf,df,acl,bcl,ccl,dcl]=h2lqg(A,B1,B2,C1,C2,D11,D12,D21,D22);
  145. %      sv=sigma(af,bf,cf,df,1,w)
  146. %
  147. % but the following is much simpler to type 
  148.  
  149. %    ( .... be patient, this computation may take awhile .... )
  150.  
  151.        w = logspace(-3,3,10);
  152.        sv=sigma(h2lqg(TSS_),1,w);
  153.  
  154. pause                % Press any key to continue
  155.  
  156. echo off
  157.        loglog(w,sv)
  158.        title('loglog(sigma(sv,1,w))')
  159. pause                % Press any key to continue
  160. clc
  161. echo on
  162.  
  163. % H-infinity control design is easy too using the SYSTEM data
  164. % structure TSS_.  To compute the HINF controller SYSTEM ss_f
  165. % and the closed-loop transfer function SYSTEM ss_cl, we type:
  166.  
  167.        [ss_f,ss_cl]=hinf(TSS_);
  168.  
  169. pause                % Press any key to continue
  170. clc
  171. % To recover the closed-loop state-space matrices [af,bf,cf,df]
  172. % from the SYSTEM vector ss_f, one may type
  173.  
  174.     [af,bf,cf,df] = branch(ss_f);
  175.  
  176.  
  177.     who
  178.  
  179.  
  180. pause                % Press any key to continue
  181. clc
  182.                            % TREE %
  183.  
  184. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185. %% The TREE function provides a general purpose tool for creating  %%
  186. %% hierarchical data structures containing matrices, strings and   %%
  187. %% even other TREEs.                                               %%
  188. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  189.  
  190. % For example, suppose one wishes to keep track of the plant 
  191. % [A,B1,B2,C1,C2,D11,D12,D21,D22], along with the control law
  192. % [af,bf,cf,df], the frequency response [w,sv] along with the
  193. % name 'Aircraft Design Data'.  No problem!
  194.  
  195. % First put the frequency response data in a TREE:
  196.             fr=tree('w,sv',w,sv);
  197.  
  198. % Now pack TSS_, ss_f, fr, along with the string 'Aircraft Design Data'
  199. % into the TREE vector DesignData:
  200. DesignData=...
  201.   tree('plant,controller,freqresp,name',TSS_,ss_f,fr,'Aircraft Design Data');
  202.  
  203. pause                % Press any key to continue
  204. clc
  205.  
  206. % The TREE DesignData has the following hierarchical structure:
  207.  
  208. %        plant
  209. %            [a,b1,b2,c1,c2,d11,d12,d21,d22,ty]
  210. %        controller
  211. %            [a,b,c,d,ty]
  212. %        freqresp
  213. %            [w,sv]
  214. %        [name]
  215.  
  216. % This TREE vector has two levels, as indicated by the indentation.
  217. % However there is in general no limit to the number of levels a TREE
  218. % vector can have. 
  219.  
  220. % To recover the variable called 'name' from the TREE vector DesignData,
  221. % we type:
  222.            name=branch(DesignData,'name')
  223. pause                % Press any key to continue
  224. clc
  225. % To see the names of all the "root branches" of the TREE DesignData, type
  226. % the following (root branch names are always in branch no. 0 of a TREE):
  227.  
  228.            branch(DesignData,0)
  229.  
  230. % The names of the root branches of the sub-tree 'plant' are returned by
  231.  
  232.            branch(DesignData,'plant/0')
  233.  
  234. pause                % Press any key to continue
  235. clc
  236.  
  237. % To recover the value of the matrix named 'c1' in the branch 'plant'
  238. % of the tree DesignData, we could define the "path" to the variable 
  239. % 'c1' in the tree as 'plant/c1'.  Namely, we can descend two levels 
  240. % into the TREE DesignData to recover the C1 matrix of the plant TSS_ 
  241. % with the command:
  242.  
  243.      C1 = branch(DesignData,'plant/c1')
  244.  
  245. pause                % Press any key to continue
  246. clc
  247.                              % SUMMARY %
  248.  
  249. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  250. %% The function MKSYS and the function TREE upon which it is based    %%
  251. %% endow matlab with a new data structure consisting of a collection  %%
  252. %% of one or more matrices, strings and even sub-TREE's.              %%
  253. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  254.  
  255. % The power to represent systems by a single symbol considerably 
  256. % simplifies user interaction with the functions in the Robust-Control
  257. % Toolbox.  However, those who don't mind typing a lot still have the
  258. % option to type in the entire list of variables describing a system
  259. % if they prefer!
  260.  
  261. echo off
  262.  
  263. % ------------ End of SYSDEMO.M -------- RYC/MGS 11/11/90 %
  264.