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

其他行业

开发平台:

Matlab

  1. function [ret,x0,str,ts,xts]=sim12p12(t,x,u,flag);
  2. %SIM12P12   is the M-file description of the SIMULINK system named SIM12P12.
  3. %   The block-diagram can be displayed by typing: SIM12P12.
  4. %
  5. %   SYS=SIM12P12(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 SIM12P12 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 SIM12P12 with a FLAG of zero:
  15. %   [SIZES]=SIM12P12([],[],[],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',[102,58,960,751])
  36.      open_system(sys)
  37. end;
  38. set_param(sys,'algorithm',     'RK-23')
  39. set_param(sys,'Start time',    '0.0')
  40. set_param(sys,'Stop time',     '15')
  41. set_param(sys,'Min step size', '0.0001')
  42. set_param(sys,'Max step size', '.05')
  43. set_param(sys,'Relative error','1e-3')
  44. set_param(sys,'Return vars',   '')
  45. add_block('built-in/Note',[sys,'/','DPm'])
  46. set_param([sys,'/','DPm'],...
  47.         'position',[300,175,305,180])
  48. add_block('built-in/Transfer Fcn',[sys,'/','Inertia & load'])
  49. set_param([sys,'/','Inertia & load'],...
  50.         'Denominator','[10  0.8]',...
  51.         'position',[415,182,495,228])
  52. add_block('built-in/Note',[sys,'/','Vref'])
  53. set_param([sys,'/','Vref'],...
  54.         'position',[35,350,40,370])
  55. add_block('built-in/Sum',[sys,'/','Sum'])
  56. set_param([sys,'/','Sum'],...
  57.         'inputs','-+-',...
  58.         'position',[365,181,390,229])
  59. add_block('built-in/Transfer Fcn',[sys,'/','Turbine'])
  60. set_param([sys,'/','Turbine'],...
  61.         'Denominator','[0.5  1]',...
  62.         'position',[205,183,275,227])
  63. add_block('built-in/Transfer Fcn',[sys,'/','Governor'])
  64. set_param([sys,'/','Governor'],...
  65.         'Denominator','[0.2   1]',...
  66.         'position',[110,182,175,228])
  67. add_block('built-in/Sum',[sys,'/','Sum1'])
  68. set_param([sys,'/','Sum1'],...
  69.         'inputs','--',...
  70.         'position',[55,187,75,223])
  71. %     Subsystem  'Graph1'.
  72. new_system([sys,'/','Graph1'])
  73. set_param([sys,'/','Graph1'],'Location',[0,59,274,252])
  74. add_block('built-in/Inport',[sys,'/','Graph1/x'])
  75. set_param([sys,'/','Graph1/x'],...
  76.         'position',[65,55,85,75])
  77. add_block('built-in/S-Function',[sys,'/',['Graph1/S-function',13,'M-file which plots',13,'lines',13,'']])
  78. set_param([sys,'/',['Graph1/S-function',13,'M-file which plots',13,'lines',13,'']],...
  79.         'function name','sfuny',...
  80.         'parameters','ax, color,dt',...
  81.         'position',[130,55,180,75])
  82. add_line([sys,'/','Graph1'],[90,65;125,65])
  83. set_param([sys,'/','Graph1'],...
  84.         '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])',...
  85.         'Mask Type','Graph scope.')
  86. set_param([sys,'/','Graph1'],...
  87.         '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 ''/'':')
  88. set_param([sys,'/','Graph1'],...
  89.         'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
  90. set_param([sys,'/','Graph1'],...
  91.         '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.')
  92. set_param([sys,'/','Graph1'],...
  93.         'Mask Entries','15/-0.04/0.005/''y-/g--/c-./w:/m*/ro/b+''/')
  94. %     Finished composite block 'Graph1'.
  95. set_param([sys,'/','Graph1'],...
  96.         'position',[560,111,590,149])
  97. add_block('built-in/Integrator',[sys,'/','Integrator1'])
  98. set_param([sys,'/','Integrator1'],...
  99.         'position',[590,187,620,223])
  100. add_block('built-in/Note',[sys,'/','Ve'])
  101. set_param([sys,'/','Ve'],...
  102.         'position',[130,384,135,391])
  103. add_block('built-in/Gain',[sys,'/','K5'])
  104. set_param([sys,'/','K5'],...
  105.         'orientation',1,...
  106.         'Gain','-0.1',...
  107.         'position',[635,325,695,375])
  108. add_block('built-in/Note',[sys,'/','Vt'])
  109. set_param([sys,'/','Vt'],...
  110.         'position',[730,375,735,380])
  111. add_block('built-in/Transfer Fcn',[sys,'/','Sensor'])
  112. set_param([sys,'/','Sensor'],...
  113.         'orientation',2,...
  114.         'Denominator','[0.05  1]',...
  115.         'position',[330,484,425,536])
  116. add_block('built-in/Note',[sys,'/',['E''']])
  117. set_param([sys,'/',['E''']],...
  118.         'position',[585,420,590,425])
  119. add_block('built-in/Sum',[sys,'/','Sum3'])
  120. set_param([sys,'/','Sum3'],...
  121.         'orientation',2,...
  122.         'position',[290,270,310,310])
  123. add_block('built-in/Transfer Fcn',[sys,'/','Generator'])
  124. set_param([sys,'/','Generator'],...
  125.         'Numerator','[0.8]',...
  126.         'Denominator','[ 1.4 1]',...
  127.         'position',[505,399,575,451])
  128. add_block('built-in/Gain',[sys,'/','K6'])
  129. set_param([sys,'/','K6'],...
  130.         'Gain','.5',...
  131.         'position',[615,400,675,450])
  132. add_block('built-in/Sum',[sys,'/','Sum5'])
  133. set_param([sys,'/','Sum5'],...
  134.         'position',[705,397,725,433])
  135. %     Subsystem  'Graph'.
  136. new_system([sys,'/','Graph'])
  137. set_param([sys,'/','Graph'],'Location',[0,59,274,252])
  138. add_block('built-in/Inport',[sys,'/','Graph/x'])
  139. set_param([sys,'/','Graph/x'],...
  140.         'position',[65,55,85,75])
  141. add_block('built-in/S-Function',[sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
  142. set_param([sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
  143.         'function name','sfuny',...
  144.         'parameters','ax, color,dt',...
  145.         'position',[130,55,180,75])
  146. add_line([sys,'/','Graph'],[90,65;125,65])
  147. set_param([sys,'/','Graph'],...
  148.         '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])',...
  149.         'Mask Type','Graph scope.')
  150. set_param([sys,'/','Graph'],...
  151.         '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 ''/'':')
  152. set_param([sys,'/','Graph'],...
  153.         'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
  154. set_param([sys,'/','Graph'],...
  155.         '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.')
  156. set_param([sys,'/','Graph'],...
  157.         'Mask Entries','15/0/1.1/''y-/g--/c-./w:/m*/ro/b+''/')
  158. %     Finished composite block 'Graph'.
  159. set_param([sys,'/','Graph'],...
  160.         'position',[780,396,810,434])
  161. add_block('built-in/Gain',[sys,'/','K4'])
  162. set_param([sys,'/','K4'],...
  163.         'orientation',1,...
  164.         'Gain','1.4',...
  165.         'position',[405,360,465,410])
  166. add_block('built-in/Gain',[sys,'/','K2'])
  167. set_param([sys,'/','K2'],...
  168.         'orientation',2,...
  169.         'Gain','.2',...
  170.         'position',[480,305,535,365])
  171. add_block('built-in/Sum',[sys,'/','Sum4'])
  172. set_param([sys,'/','Sum4'],...
  173.         'inputs','-+',...
  174.         'position',[455,407,475,443])
  175. add_block('built-in/Gain',[sys,'/','K1=Ps'])
  176. set_param([sys,'/','K1=Ps'],...
  177.         'orientation',2,...
  178.         'Gain','1.5',...
  179.         'position',[355,253,405,307])
  180. add_block('built-in/Note',[sys,'/','VR'])
  181. set_param([sys,'/','VR'],...
  182.         'position',[305,380,335,386])
  183. add_block('built-in/Step Fcn',[sys,'/','Step Input1'])
  184. set_param([sys,'/','Step Input1'],...
  185.         'Time','12',...
  186.         'Before','1',...
  187.         'position',[20,407,60,443])
  188. add_block('built-in/Sum',[sys,'/','Sum2'])
  189. set_param([sys,'/','Sum2'],...
  190.         'inputs','+-',...
  191.         'position',[100,415,135,455])
  192. %     Subsystem  'PID Controller'.
  193. new_system([sys,'/','PID Controller'])
  194. set_param([sys,'/','PID Controller'],'Location',[0,0,362,244])
  195. add_block('built-in/Sum',[sys,'/','PID Controller/Sum'])
  196. set_param([sys,'/','PID Controller/Sum'],...
  197.         'inputs','+++',...
  198.         'position',[245,57,265,93])
  199. add_block('built-in/Gain',[sys,'/','PID Controller/D'])
  200. set_param([sys,'/','PID Controller/D'],...
  201.         'Gain','D',...
  202.         'position',[95,129,115,151])
  203. add_block('built-in/Gain',[sys,'/','PID Controller/Proportional'])
  204. set_param([sys,'/','PID Controller/Proportional'],...
  205.         'Gain','P',...
  206.         'position',[120,13,140,37])
  207. add_block('built-in/Transfer Fcn',[sys,'/','PID Controller/Integral'])
  208. set_param([sys,'/','PID Controller/Integral'],...
  209.         'Numerator','[I]',...
  210.         'Denominator','[1 0]',...
  211.         'position',[110,57,145,93])
  212. add_block('built-in/Derivative',[sys,'/','PID Controller/Derivative'])
  213. set_param([sys,'/','PID Controller/Derivative'],...
  214.         'position',[150,128,190,152])
  215. add_block('built-in/Outport',[sys,'/','PID Controller/Out_1'])
  216. set_param([sys,'/','PID Controller/Out_1'],...
  217.         'position',[290,65,310,85])
  218. add_block('built-in/Inport',[sys,'/','PID Controller/In_1'])
  219. set_param([sys,'/','PID Controller/In_1'],...
  220.         'position',[25,65,45,85])
  221. add_line([sys,'/','PID Controller'],[120,140;145,140])
  222. add_line([sys,'/','PID Controller'],[270,75;285,75])
  223. add_line([sys,'/','PID Controller'],[50,75;105,75])
  224. add_line([sys,'/','PID Controller'],[65,75;65,140;90,140])
  225. add_line([sys,'/','PID Controller'],[80,75;80,25;115,25])
  226. add_line([sys,'/','PID Controller'],[195,140;215,140;215,85;240,85])
  227. add_line([sys,'/','PID Controller'],[150,75;240,75])
  228. add_line([sys,'/','PID Controller'],[145,25;210,25;210,65;240,65])
  229. set_param([sys,'/','PID Controller'],...
  230.         'Mask Display','PID',...
  231.         'Mask Type','PID Controller',...
  232.         'Mask Dialogue','Enter expressions for proportional, integral, and derivative terms.nP+I/s+Ds|Proportional:|Integral|Derivative:')
  233. set_param([sys,'/','PID Controller'],...
  234.         'Mask Translate','P=@1; I=@2; D=@3;')
  235. set_param([sys,'/','PID Controller'],...
  236.         'Mask Help','This block implements a PID controller where parameters are entered for the Proportional, Integral and Derivative terms. Unmask this block to see how it works. The derivative term is implemented using a true derivative block.')
  237. set_param([sys,'/','PID Controller'],...
  238.         'Mask Entries','1/0.25/0.3/')
  239. %     Finished composite block 'PID Controller'.
  240. set_param([sys,'/','PID Controller'],...
  241.         'position',[170,419,210,451])
  242. add_block('built-in/Transfer Fcn',[sys,'/','Exciter'])
  243. set_param([sys,'/','Exciter'],...
  244.         'Numerator','1',...
  245.         'Denominator','[0.4  1]',...
  246.         'position',[335,411,405,459])
  247. add_block('built-in/Note',[sys,'/','Vf'])
  248. set_param([sys,'/','Vf'],...
  249.         'position',[415,405,420,410])
  250. add_block('built-in/Transfer Fcn',[sys,'/','Amplifier'])
  251. set_param([sys,'/','Amplifier'],...
  252.         'Numerator','10',...
  253.         'Denominator','[0.1  1]',...
  254.         'position',[240,409,310,461])
  255. add_block('built-in/Gain',[sys,'/','1//R'])
  256. set_param([sys,'/','1//R'],...
  257.         'orientation',2,...
  258.         'Gain','20',...
  259.         'position',[230,103,285,157])
  260. add_block('built-in/Step Fcn',[sys,'/','Step Input'])
  261. set_param([sys,'/','Step Input'],...
  262.         'orientation',1,...
  263.         'Time','2',...
  264.         'Before','0.2',...
  265.         'After','.2',...
  266.         'position',[320,140,340,160])
  267. add_block('built-in/Integrator',[sys,'/','Integrator'])
  268. set_param([sys,'/','Integrator'],...
  269.         'orientation',2,...
  270.         'position',[155,68,185,112])
  271. add_block('built-in/Gain',[sys,'/','KI'])
  272. set_param([sys,'/','KI'],...
  273.         'orientation',2,...
  274.         'Gain','6',...
  275.         'position',[65,67,115,113])
  276. add_block('built-in/Note',[sys,'/','Dd'])
  277. set_param([sys,'/','Dd'],...
  278.         'position',[645,175,650,180])
  279. add_block('built-in/Note',[sys,'/','Dw'])
  280. set_param([sys,'/','Dw'],...
  281.         'position',[535,210,540,215])
  282. add_line(sys,[180,205;200,205])
  283. add_line(sys,[280,205;360,205])
  284. add_line(sys,[395,205;410,205])
  285. add_line(sys,[80,205;105,205])
  286. add_line(sys,[330,165;330,190;360,190])
  287. add_line(sys,[65,425;95,425])
  288. add_line(sys,[325,510;85,510;95,445])
  289. add_line(sys,[315,435;330,435])
  290. add_line(sys,[140,435;165,435])
  291. add_line(sys,[215,435;235,435])
  292. add_line(sys,[285,290;285,220;360,220])
  293. add_line(sys,[500,205;585,205])
  294. add_line(sys,[530,205;530,130;555,130])
  295. add_line(sys,[410,435;450,435])
  296. add_line(sys,[480,425;500,425])
  297. add_line(sys,[580,425;610,425])
  298. add_line(sys,[680,425;700,425])
  299. add_line(sys,[350,280;315,280])
  300. add_line(sys,[665,380;665,405;700,405])
  301. add_line(sys,[730,415;775,415])
  302. add_line(sys,[740,415;740,510;430,510])
  303. add_line(sys,[590,425;590,335;540,335])
  304. add_line(sys,[435,415;450,415])
  305. add_line(sys,[475,335;335,335;335,300;315,300])
  306. add_line(sys,[225,130;215,130;215,165;40,165;50,195])
  307. add_line(sys,[150,90;120,90])
  308. add_line(sys,[60,90;25,90;25,215;50,215])
  309. add_line(sys,[625,205;665,205;665,320])
  310. add_line(sys,[665,280;410,280])
  311. add_line(sys,[520,205;520,90;190,90])
  312. add_line(sys,[520,130;290,130])
  313. add_line(sys,[435,280;435,355])
  314. drawnow
  315. % Return any arguments.
  316. if (nargin | nargout)
  317.     % Must use feval here to access system in memory
  318.     if (nargin > 3)
  319.         if (flag == 0)
  320.             eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
  321.         else
  322.             eval(['ret =', sys,'(t,x,u,flag);'])
  323.         end
  324.     else
  325.         [ret,x0,str,ts,xts] = feval(sys);
  326.     end
  327. else
  328.     drawnow % Flash up the model and execute load callback
  329. end