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

📄 lab03.m

📁 xnsy算法的matlab实现
💻 M
字号:
function [ret,x0,str,ts,xts]=lab03(t,x,u,flag);
%LAB03	is the M-file description of the SIMULINK system named LAB03.
%	The block-diagram can be displayed by typing: LAB03.
%
%	SYS=LAB03(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 LAB03 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 LAB03 with a FLAG of zero:
%	[SIZES]=LAB03([],[],[],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
%		SIZES(5) number of roots (currently unsupported)
%		SIZES(6) direct feedthrough flag
%		SIZES(7) number of sample times
%
%	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.3)
if (0 == (nargin + nargout))
     set_param(sys,'Location',[10,101,175,455])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '999999')
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/Sum',[sys,'/','加法器'])
set_param([sys,'/','加法器'],...
		'position',[35,45,55,65])

add_block('built-in/Integrator',[sys,'/','积分器'])
set_param([sys,'/','积分器'],...
		'position',[100,50,120,70])

add_block('built-in/Gain',[sys,'/','放大器'])
set_param([sys,'/','放大器'],...
		'position',[35,100,55,120])


%     Subsystem  'PID 控制器'.

new_system([sys,'/','PID 控制器'])
set_param([sys,'/','PID 控制器'],'Location',[0,0,362,244])

add_block('built-in/Sum',[sys,'/','PID 控制器/Sum'])
set_param([sys,'/','PID 控制器/Sum'],...
		'inputs','+++',...
		'position',[245,57,265,93])

add_block('built-in/Gain',[sys,'/','PID 控制器/D'])
set_param([sys,'/','PID 控制器/D'],...
		'Gain','D',...
		'position',[95,129,115,151])

add_block('built-in/Gain',[sys,'/','PID 控制器/Proportional'])
set_param([sys,'/','PID 控制器/Proportional'],...
		'Gain','P',...
		'position',[120,13,140,37])

add_block('built-in/Transfer Fcn',[sys,'/','PID 控制器/Integral'])
set_param([sys,'/','PID 控制器/Integral'],...
		'Numerator','[I]',...
		'Denominator','[1 0]',...
		'position',[110,57,145,93])

add_block('built-in/Derivative',[sys,'/','PID 控制器/Derivative'])
set_param([sys,'/','PID 控制器/Derivative'],...
		'position',[150,128,190,152])

add_block('built-in/Outport',[sys,'/','PID 控制器/Out_1'])
set_param([sys,'/','PID 控制器/Out_1'],...
		'position',[290,65,310,85])

add_block('built-in/Inport',[sys,'/','PID 控制器/In_1'])
set_param([sys,'/','PID 控制器/In_1'],...
		'position',[25,65,45,85])
add_line([sys,'/','PID 控制器'],[120,140;145,140])
add_line([sys,'/','PID 控制器'],[270,75;285,75])
add_line([sys,'/','PID 控制器'],[50,75;105,75])
add_line([sys,'/','PID 控制器'],[65,75;65,140;90,140])
add_line([sys,'/','PID 控制器'],[80,75;80,25;115,25])
add_line([sys,'/','PID 控制器'],[195,140;215,140;215,85;240,85])
add_line([sys,'/','PID 控制器'],[150,75;240,75])
add_line([sys,'/','PID 控制器'],[145,25;210,25;210,65;240,65])
set_param([sys,'/','PID 控制器'],...
		'Mask Display','PID',...
		'Mask Type','PID Controller',...
		'Mask Dialogue','Enter expressions for proportional, integral, and derivitive terms.|Proportional:|Integral|Derivitive:')
set_param([sys,'/','PID 控制器'],...
		'Mask Translate','P=@1; I=@2; D=@3;')
set_param([sys,'/','PID 控制器'],...
		'Mask Help','This block implements a PID controller where paramaters are entered for the Proportional, Integral and Derivitive terms. Unmask this block to see how it works. The derivative term is implemented using a true derivative block.')
set_param([sys,'/','PID 控制器'],...
		'Mask Entries','1\/1\/0\/')


%     Finished composite block 'PID 控制器'.

set_param([sys,'/','PID 控制器'],...
		'position',[30,229,70,261])

add_block('built-in/Transfer Fcn',[sys,'/','S传递函数'])
set_param([sys,'/','S传递函数'],...
		'Denominator','[1 1]',...
		'position',[25,152,60,188])

add_block('built-in/Derivative',[sys,'/','微分器'])
set_param([sys,'/','微分器'],...
		'position',[100,110,130,130])

add_block('built-in/Zero-Pole',[sys,'/','S零极点传函'])
set_param([sys,'/','S零极点传函'],...
		'Poles','[0; -1]',...
		'position',[95,152,140,188])

add_block('built-in/Mux',[sys,'/','综合器'])
set_param([sys,'/','综合器'],...
		'inputs','3',...
		'position',[105,229,135,261])

add_block('built-in/Note',[sys,'/','线性连续环节'])
set_param([sys,'/','线性连续环节'],...
		'ForeGround',4,...
		'Font Size',14,...
		'position',[75,10,80,15])

drawnow

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
else
	drawnow % Flash up the model and execute load callback
end

⌨️ 快捷键说明

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