Sim12ex5.m
上传用户:eighthdate
上传日期:2014-05-24
资源大小:270k
文件大小:11k
源码类别:

其他行业

开发平台:

Matlab

  1. function [ret,x0,str,ts,xts]=chp12sm5(t,x,u,flag);
  2. %CHP12SM5   is the M-file description of the SIMULINK system named CHP12SM5.
  3. %   The block-diagram can be displayed by typing: CHP12SM5.
  4. %
  5. %   SYS=CHP12SM5(T,X,U,FLAG) returns depending on FLAG certain
  6. %   system values given time point, T, current state vector, X,
  7. %   and input vector, U.
  8. %   FLAG is used to indicate the type of output to be returned in SYS.
  9. %
  10. %   Setting FLAG=1 causes CHP12SM5 to return state derivatives, FLAG=2
  11. %   discrete states, FLAG=3 system outputs and FLAG=4 next sample
  12. %   time. For more information and other options see SFUNC.
  13. %
  14. %   Calling CHP12SM5 with a FLAG of zero:
  15. %   [SIZES]=CHP12SM5([],[],[],0),  returns a vector, SIZES, which
  16. %   contains the sizes of the state vector and other parameters.
  17. %       SIZES(1) number of states
  18. %       SIZES(2) number of discrete states
  19. %       SIZES(3) number of outputs
  20. %       SIZES(4) number of inputs
  21. %       SIZES(5) number of roots (currently unsupported)
  22. %       SIZES(6) direct feedthrough flag
  23. %       SIZES(7) number of sample times
  24. %
  25. %   For the definition of other parameters in SIZES, see SFUNC.
  26. %   See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
  27. % Note: This M-file is only used for saving graphical information;
  28. %       after the model is loaded into memory an internal model
  29. %       representation is used.
  30. % the system will take on the name of this mfile:
  31. sys = mfilename;
  32. new_system(sys)
  33. simver(1.3)
  34. if (0 == (nargin + nargout))
  35.      set_param(sys,'Location',[54,58,902,751])
  36.      open_system(sys)
  37. end;
  38. set_param(sys,'algorithm',     'RK-45')
  39. set_param(sys,'Start time',    '0.0')
  40. set_param(sys,'Stop time',     '25')
  41. set_param(sys,'Min step size', '0.001')
  42. set_param(sys,'Max step size', '.1')
  43. set_param(sys,'Relative error','1e-3')
  44. set_param(sys,'Return vars',   '')
  45. add_block('built-in/Transfer Fcn',[sys,'/','Inertia & load 2'])
  46. set_param([sys,'/','Inertia & load 2'],...
  47.         'Denominator','[8  0.9]',...
  48.         'position',[645,402,725,448])
  49. add_block('built-in/Sum',[sys,'/','Sum3'])
  50. set_param([sys,'/','Sum3'],...
  51.         'position',[580,407,600,443])
  52. add_block('built-in/Sum',[sys,'/','Sum4'])
  53. set_param([sys,'/','Sum4'],...
  54.         'inputs','+-',...
  55.         'position',[265,417,285,453])
  56. add_block('built-in/Transfer Fcn',[sys,'/','   Governor 2'])
  57. set_param([sys,'/','   Governor 2'],...
  58.         'Denominator','[0.3   1]',...
  59.         'position',[335,412,400,458])
  60. %     Subsystem  ['Dw1',13,'Dw2 '].
  61. new_system([sys,'/',['Dw1',13,'Dw2 ']])
  62. set_param([sys,'/',['Dw1',13,'Dw2 ']],'Location',[0,59,274,252])
  63. add_block('built-in/S-Function',[sys,'/',['Dw1',13,'Dw2 /S-function',13,'M-file which plots',13,'lines',13,'']])
  64. set_param([sys,'/',['Dw1',13,'Dw2 /S-function',13,'M-file which plots',13,'lines',13,'']],...
  65.         'function name','sfuny',...
  66.         'parameters','ax, color,dt',...
  67.         'position',[130,55,180,75])
  68. add_block('built-in/Inport',[sys,'/',['Dw1',13,'Dw2 /x']])
  69. set_param([sys,'/',['Dw1',13,'Dw2 /x']],...
  70.         'position',[65,55,85,75])
  71. add_line([sys,'/',['Dw1',13,'Dw2 ']],[90,65;125,65])
  72. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  73.         'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
  74.         'Mask Type','Graph scope.')
  75. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  76.         'Mask Dialogue','Graph scope using MATLAB graph window.nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
  77. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  78.         'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
  79. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  80.         'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
  81. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  82.         'Mask Entries','25/-.015/0.015/''y-/g--/c-./w:/m*/ro/b+''/')
  83. %     Finished composite block ['Dw1',13,'Dw2 '].
  84. set_param([sys,'/',['Dw1',13,'Dw2 ']],...
  85.         'orientation',1,...
  86.         'position',[770,505,800,545])
  87. add_block('built-in/Mux',[sys,'/','Mux'])
  88. set_param([sys,'/','Mux'],...
  89.         'orientation',1,...
  90.         'inputs','2',...
  91.         'position',[767,445,798,480])
  92. add_block('built-in/Mux',[sys,'/','Mux1'])
  93. set_param([sys,'/','Mux1'],...
  94.         'orientation',1,...
  95.         'inputs','3',...
  96.         'position',[855,445,895,485])
  97. add_block('built-in/Clock',[sys,'/','Clock'])
  98. set_param([sys,'/','Clock'],...
  99.         'orientation',1,...
  100.         'position',[850,350,870,370])
  101. add_block('built-in/Transfer Fcn',[sys,'/','Turbine 2'])
  102. set_param([sys,'/','Turbine 2'],...
  103.         'Denominator','[0.6  1]',...
  104.         'position',[460,413,530,457])
  105. add_block('built-in/To Workspace',[sys,'/',['t  ',13,'Dw1',13,'Dw2']])
  106. set_param([sys,'/',['t  ',13,'Dw1',13,'Dw2']],...
  107.         'orientation',1,...
  108.         'mat-name','Dw',...
  109.         'position',[850,500,900,545])
  110. add_block('built-in/Gain',[sys,'/','Gain'])
  111. set_param([sys,'/','Gain'],...
  112.         'orientation',2,...
  113.         'Gain','2',...
  114.         'position',[580,331,620,369])
  115. add_block('built-in/Gain',[sys,'/',['1//R2',13,'']])
  116. set_param([sys,'/',['1//R2',13,'']],...
  117.         'orientation',2,...
  118.         'Gain','16',...
  119.         'position',[495,492,550,538])
  120. add_block('built-in/Gain',[sys,'/','1//R1'])
  121. set_param([sys,'/','1//R1'],...
  122.         'orientation',2,...
  123.         'Gain','20',...
  124.         'position',[485,112,530,158])
  125. add_block('built-in/Transfer Fcn',[sys,'/',' Turbine 1'])
  126. set_param([sys,'/',' Turbine 1'],...
  127.         'Denominator','[0.5  1]',...
  128.         'position',[455,208,525,252])
  129. add_block('built-in/Transfer Fcn',[sys,'/',' Governor 1'])
  130. set_param([sys,'/',' Governor 1'],...
  131.         'Denominator','[0.2   1]',...
  132.         'position',[335,207,400,253])
  133. add_block('built-in/Sum',[sys,'/','Sum1'])
  134. set_param([sys,'/','Sum1'],...
  135.         'inputs','-+',...
  136.         'position',[255,212,275,248])
  137. add_block('built-in/Sum',[sys,'/','Sum'])
  138. set_param([sys,'/','Sum'],...
  139.         'inputs','-+-',...
  140.         'position',[570,212,590,248])
  141. add_block('built-in/Transfer Fcn',[sys,'/',['Inertia & load 1',13,'']])
  142. set_param([sys,'/',['Inertia & load 1',13,'']],...
  143.         'Denominator','[10  0.6]',...
  144.         'position',[645,207,725,253])
  145. add_block('built-in/Step Fcn',[sys,'/',['DPL',13,'']])
  146. set_param([sys,'/',['DPL',13,'']],...
  147.         'orientation',1,...
  148.         'Time','100',...
  149.         'Before','0.1875',...
  150.         'After','.1875',...
  151.         'position',[545,175,565,195])
  152. add_block('built-in/Mux',[sys,'/','Mux2'])
  153. set_param([sys,'/','Mux2'],...
  154.         'orientation',2,...
  155.         'position',[370,282,410,328])
  156. add_block('built-in/Clock',[sys,'/','Clock1'])
  157. set_param([sys,'/','Clock1'],...
  158.         'orientation',2,...
  159.         'position',[460,280,480,300])
  160. add_block('built-in/To Workspace',[sys,'/','t, Pm1, Pm2, P12'])
  161. set_param([sys,'/','t, Pm1, Pm2, P12'],...
  162.         'orientation',2,...
  163.         'mat-name','DP',...
  164.         'position',[230,295,320,315])
  165. add_block('built-in/Sum',[sys,'/','ACE1'])
  166. set_param([sys,'/','ACE1'],...
  167.         'inputs','--',...
  168.         'position',[50,230,70,250])
  169. add_block('built-in/Sum',[sys,'/','ACE2'])
  170. set_param([sys,'/','ACE2'],...
  171.         'inputs','+-',...
  172.         'position',[50,415,70,435])
  173. add_block('built-in/Gain',[sys,'/','B1=1//R1+D1'])
  174. set_param([sys,'/','B1=1//R1+D1'],...
  175.         'orientation',2,...
  176.         'Gain','20.6',...
  177.         'position',[385,48,450,102])
  178. add_block('built-in/Gain',[sys,'/','B2=1//R2+D2'])
  179. set_param([sys,'/','B2=1//R2+D2'],...
  180.         'orientation',2,...
  181.         'Gain','16.9',...
  182.         'position',[440,541,495,589])
  183. add_block('built-in/Integrator',[sys,'/','Integrator2'])
  184. set_param([sys,'/','Integrator2'],...
  185.         'position',[130,407,165,443])
  186. add_block('built-in/Integrator',[sys,'/','Integrator1'])
  187. set_param([sys,'/','Integrator1'],...
  188.         'position',[130,223,160,257])
  189. add_block('built-in/Gain',[sys,'/','KI2 '])
  190. set_param([sys,'/','KI2 '],...
  191.         'Gain','.3',...
  192.         'position',[190,408,230,442])
  193. add_block('built-in/Gain',[sys,'/','KI1'])
  194. set_param([sys,'/','KI1'],...
  195.         'Gain','.3',...
  196.         'position',[190,223,220,257])
  197. add_block('built-in/Integrator',[sys,'/','Integrator'])
  198. set_param([sys,'/','Integrator'],...
  199.         'orientation',2,...
  200.         'position',[650,333,680,367])
  201. add_block('built-in/Sum',[sys,'/','Sum2'])
  202. set_param([sys,'/','Sum2'],...
  203.         'orientation',2,...
  204.         'inputs','+-',...
  205.         'position',[710,334,730,361])
  206. add_line(sys,[405,230;450,230])
  207. add_line(sys,[530,230;565,230])
  208. add_line(sys,[595,230;640,230])
  209. add_line(sys,[280,230;330,230])
  210. add_line(sys,[730,230;755,230;755,135;535,135])
  211. add_line(sys,[555,200;565,220])
  212. add_line(sys,[480,135;220,135;220,220;250,220])
  213. add_line(sys,[705,350;685,350])
  214. add_line(sys,[645,350;625,350])
  215. add_line(sys,[605,425;640,425])
  216. add_line(sys,[405,435;455,435])
  217. add_line(sys,[290,435;330,435])
  218. add_line(sys,[535,435;575,435])
  219. add_line(sys,[490,515;235,515;235,445;260,445])
  220. add_line(sys,[730,425;755,425;755,515;555,515])
  221. add_line(sys,[365,305;325,305])
  222. add_line(sys,[455,290;415,290])
  223. add_line(sys,[730,425;755,425;755,355;735,355])
  224. add_line(sys,[730,230;755,230;755,340;735,340])
  225. add_line(sys,[785,485;785,500])
  226. add_line(sys,[875,490;875,495])
  227. add_line(sys,[730,425;890,425;890,440])
  228. add_line(sys,[860,375;860,440])
  229. add_line(sys,[730,230;775,230;775,440])
  230. add_line(sys,[730,425;790,425;790,440])
  231. add_line(sys,[730,230;775,230;775,402;875,402;875,440])
  232. add_line(sys,[575,350;555,350;565,240])
  233. add_line(sys,[575,350;555,350;555,415;575,415])
  234. add_line(sys,[405,435;435,435;435,310;415,310])
  235. add_line(sys,[405,230;435,230;435,300;415,300])
  236. add_line(sys,[225,240;250,240])
  237. add_line(sys,[165,240;185,240])
  238. add_line(sys,[75,240;125,240])
  239. add_line(sys,[555,350;20,350;20,245;45,245])
  240. add_line(sys,[170,425;185,425])
  241. add_line(sys,[75,425;125,425])
  242. add_line(sys,[235,425;260,425])
  243. add_line(sys,[380,75;20,75;20,235;45,235])
  244. add_line(sys,[755,140;755,75;455,75])
  245. add_line(sys,[20,350;20,420;45,420])
  246. add_line(sys,[435,565;20,565;20,430;45,430])
  247. add_line(sys,[755,515;755,565;500,565])
  248. add_line(sys,[425,350;415,320])
  249. drawnow
  250. % Return any arguments.
  251. if (nargin | nargout)
  252.     % Must use feval here to access system in memory
  253.     if (nargin > 3)
  254.         if (flag == 0)
  255.             eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
  256.         else
  257.             eval(['ret =', sys,'(t,x,u,flag);'])
  258.         end
  259.     else
  260.         [ret,x0,str,ts,xts] = feval(sys);
  261.     end
  262. else
  263.     drawnow % Flash up the model and execute load callback
  264. end