⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pensim_s.m

📁 FISMAT accommodates different arithmetic operators, fuzzification and defuzzification algorithm, imp
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret,x0,str]=pensim_s(t,x,u,flag);%PENSIM_S	is the M-file description of the SIMULINK system named PENSIM_S.%	The block-diagram can be displayed by typing: PENSIM_S.%%	SYS=PENSIM_S(T,X,U,FLAG) returns depending on FLAG certain%	system values given time point, T, current state vector, X,%	and input vector, U.%	FLAG is used to indicate the type of output to be returned in SYS.%%	Setting FLAG=1 causes PENSIM_S to return state derivatives, FLAG=2%	discrete states, FLAG=3 system outputs and FLAG=4 next sample%	time. For more information and other options see SFUNC.%%	Calling PENSIM_S with a FLAG of zero:%	[SIZES]=PENSIM_S([],[],[],0),  returns a vector, SIZES, which%	contains the sizes of the state vector and other parameters.%		SIZES(1) number of states%		SIZES(2) number of discrete states%		SIZES(3) number of outputs%		SIZES(4) number of inputs.%	For the definition of other parameters in SIZES, see SFUNC.%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.% Note: This M-file is only used for saving graphical information;%       after the model is loaded into memory an internal model%       representation is used.% the system will take on the name of this mfile:sys = mfilename;new_system(sys)simver(1.2)if(0 == (nargin + nargout))     set_param(sys,'Location',[4,124,628,460])     open_system(sys)end;set_param(sys,'algorithm',		'RK-45')set_param(sys,'Start time',	'0')set_param(sys,'Stop time',		'20')set_param(sys,'Min step size',	'0.0001')set_param(sys,'Max step size',	'10')set_param(sys,'Relative error','1e-3')set_param(sys,'Return vars',	'')add_block('built-in/Note',[sys,'/',['Inverted pendulum on cart with Animation',13,'(Double click on the "?" for more info)']])set_param([sys,'/',['Inverted pendulum on cart with Animation',13,'(Double click on the "?" for more info)']],...		'position',[276,20,277,21])%     Subsystem  'Pendulum'.new_system([sys,'/','Pendulum'])set_param([sys,'/','Pendulum'],'Location',[97,238,630,546])add_block('built-in/Fcn',[sys,'/','Pendulum/Fcn2'])set_param([sys,'/','Pendulum/Fcn2'],...		'hide name',0,...		'Expr','(-u[1]*cos(u[3])/m + (M+m)*g*sin(u[3])/m - l*power(u[2],2)*sin(u[3])*cos(u[3]))/(l*(M/m + power(sin(u[3]),2)))',...		'position',[210,175,250,195])add_block('built-in/Integrator',[sys,'/','Pendulum/Integrator4'])set_param([sys,'/','Pendulum/Integrator4'],...		'position',[305,90,325,110])add_block('built-in/Mux',[sys,'/','Pendulum/Mux1'])set_param([sys,'/','Pendulum/Mux1'],...		'hide name',0,...		'inputs','3',...		'position',[140,84,170,116])add_block('built-in/Fcn',[sys,'/','Pendulum/Fcn1'])set_param([sys,'/','Pendulum/Fcn1'],...		'hide name',0,...		'Expr','(u[1]/m - g*sin(u[3])*cos(u[3]) + l*power(u[2],2)*sin(u[3]))/(M/m + power(sin(u[3]),2))',...		'position',[210,90,250,110])add_block('built-in/Mux',[sys,'/','Pendulum/Mux'])set_param([sys,'/','Pendulum/Mux'],...		'hide name',0,...		'inputs','3',...		'position',[140,169,170,201])add_block('built-in/Integrator',[sys,'/','Pendulum/Integrator1'])set_param([sys,'/','Pendulum/Integrator1'],...		'position',[385,90,405,110])add_block('built-in/Integrator',[sys,'/','Pendulum/Integrator3'])set_param([sys,'/','Pendulum/Integrator3'],...		'position',[305,175,325,195])add_block('built-in/Integrator',[sys,'/','Pendulum/Integrator2'])set_param([sys,'/','Pendulum/Integrator2'],...		'position',[385,175,405,195])add_block('built-in/Inport',[sys,'/','Pendulum/in_1'])set_param([sys,'/','Pendulum/in_1'],...		'position',[15,80,35,100])add_block('built-in/Outport',[sys,'/','Pendulum/out_1'])set_param([sys,'/','Pendulum/out_1'],...		'position',[470,90,490,110])add_block('built-in/Outport',[sys,'/','Pendulum/out_2'])set_param([sys,'/','Pendulum/out_2'],...		'Port','2',...		'position',[470,105,490,125])add_line([sys,'/','Pendulum'],[410,185;450,185;450,115;460,115])add_line([sys,'/','Pendulum'],[430,185;430,235;75,235;75,195;130,195])add_line([sys,'/','Pendulum'],[330,185;375,185])add_line([sys,'/','Pendulum'],[355,185;355,215;105,215;105,185;130,185])add_line([sys,'/','Pendulum'],[420,185;420,130;100,130;100,110;130,110])add_line([sys,'/','Pendulum'],[40,90;130,90])add_line([sys,'/','Pendulum'],[40,90;45,175;130,175])add_line([sys,'/','Pendulum'],[347,185;347,150;85,150;85,100;130,100])add_line([sys,'/','Pendulum'],[330,100;375,100])add_line([sys,'/','Pendulum'],[255,100;295,100])add_line([sys,'/','Pendulum'],[175,100;200,100])add_line([sys,'/','Pendulum'],[175,185;200,185])add_line([sys,'/','Pendulum'],[255,185;295,185])add_line([sys,'/','Pendulum'],[410,100;460,100])set_param([sys,'/','Pendulum'],...		'Mask Display','',...		'Mask Type','Inverted pendulum on cart')set_param([sys,'/','Pendulum'],...		'Mask Dialogue','Unmask and double-click to see dynamics|Mass of cart (kg):|Mass of pendulum (kg):|Distance to pendulum center of mass(m):|Acceleration of gravity (m/s^2):')set_param([sys,'/','Pendulum'],...		'Mask Translate','M=@1; m=@2; l=@3; g=@4;',...		'Mask Help','Nonlinear dynamics of inverted pendulum on cart.',...		'Mask Entries','0.455\/0.21\/0.61/2\/9.8\/')%     Finished composite block 'Pendulum'.set_param([sys,'/','Pendulum'],...		'position',[450,142,480,193])%     Subsystem  'Discrete State Estimator'.new_system([sys,'/','Discrete State Estimator'])set_param([sys,'/','Discrete State Estimator'],'Location',[380,440,840,612])add_block('built-in/Discrete State-space',[sys,'/','Discrete State Estimator/Dis. State-space'])set_param([sys,'/','Discrete State Estimator/Dis. State-space'],...		'A','zeros(2)',...		'B','-eye(2)/Ts',...		'C','[0 0; 1 0; 0 0; 0 1]',...		'D','[1 0; 1/Ts 0; 0 1; 0 1/Ts]',...		'Sample time','Ts',...		'position',[115,65,235,105])add_block('built-in/Mux',[sys,'/','Discrete State Estimator/Mux2'])set_param([sys,'/','Discrete State Estimator/Mux2'],...		'hide name',0,...		'inputs','2',...		'position',[55,55,80,110])add_block('built-in/Inport',[sys,'/','Discrete State Estimator/in_1'])set_param([sys,'/','Discrete State Estimator/in_1'],...		'position',[15,60,35,80])add_block('built-in/Outport',[sys,'/','Discrete State Estimator/out_1'])set_param([sys,'/','Discrete State Estimator/out_1'],...		'position',[260,75,280,95])add_block('built-in/Inport',[sys,'/','Discrete State Estimator/in_2'])set_param([sys,'/','Discrete State Estimator/in_2'],...		'Port','2',...		'position',[15,85,35,105])add_line([sys,'/','Discrete State Estimator'],[85,85;105,85])add_line([sys,'/','Discrete State Estimator'],[40,70;45,70])add_line([sys,'/','Discrete State Estimator'],[240,85;250,85])add_line([sys,'/','Discrete State Estimator'],[40,95;45,95])set_param([sys,'/','Discrete State Estimator'],...		'Mask Display','',...		'Mask Type','Pendulum Discrete state estimator',...		'Mask Dialogue','Pendulum discrete state estimator|Sample time',...		'Mask Translate','Ts = @1')set_param([sys,'/','Discrete State Estimator'],...		'Mask Help','The states of the pendulum and cart system are the pendulum angle and angular velocity and cart position and velocity.  Since the sensors output the pendulum angle and cart position, this state estimator just does a one step difference calculation to get the velocities.')set_param([sys,'/','Discrete State Estimator'],...		'Mask Entries','0.02\/')%     Finished composite block 'Discrete State Estimator'.set_param([sys,'/','Discrete State Estimator'],...		'position',[600,192,630,243])add_block('built-in/State-space',[sys,'/','Matrix gain.'])set_param([sys,'/','Matrix gain.'],...		'hide name',0,...		'A','[]',...		'B','[]',...		'C','[]',...		'D','K',...		'Mask Display','LQR',...		'Mask Type','Matrix gain',...		'Mask Dialogue','Matrix Gain:|Gain matrix:')set_param([sys,'/','Matrix gain.'],...		'Mask Translate','K = @1;',...		'Mask Help','Multiplies input vector by entered matrix to produce output vector.',...		'Mask Entries','[0 -18 -166.5 -15.2]\/',...		'position',[660,204,725,236])add_block('built-in/Sum',[sys,'/','Sum3'])set_param([sys,'/','Sum3'],...		'hide name',0,...		'position',[85,160,105,180])add_block('built-in/Constant',[sys,'/','Constant'])set_param([sys,'/','Constant'],...		'Value','-3',...		'position',[10,215,60,235])add_block('built-in/Signal Generator',[sys,'/','Signal Gen.'])set_param([sys,'/','Signal Gen.'],...		'hide name',0,...		'Peak','3.000000',...		'Peak Range','0.000000',...		'Freq','0.314000',...		'Freq Range','1.000000',...		'Wave','Sqr',...		'Units','Rads')open_system([sys,'/','Signal Gen.'])set_param([sys,'/','Signal Gen.'],...		'position',[10,148,55,182])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -