|
楼主 |
发表于 2010-3-22 11:29
|
显示全部楼层
回复 7楼 yufeng 的帖子
感谢指教!! 我把程序改了一下,里面没有设置迭代次数 K 但是能运行 麻烦帮我看一下哪个地方不对。小弟先谢了!
function [sys,x0,str,ts] = MIIC(t,x,u,flag,a)
global a
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(a);
case 1,
sys=mdlderivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,a);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error('unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes(a)
% Call function simsizes to create the sizes structure.
sizes = simsizes;
% Load the sizes structure with the initialization information.
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs= 1;
sizes.NumInputs= 3;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
% Load the sys vector with the sizes information.
sys = simsizes(sizes);
%
x0 = []; % No continuous states
%
str = []; % No state ordering
%
ts = [-1 0]; % Inherited sample time
% End of mdlInitializeSizes.
function sys=mdlDerivatives(t,x,u)
sys=[];
function sys=mdlUpdate(t,x,u)
sys=[];
%==============================================================
% Function mdlOutputs performs the calculations.
%==============================================================
function sys = mdlOutputs(t,x,u,a)
% U =u(1);
% Z =u(2);
% Zd=u(3);
for k=0:1:20
if k<1
u(1)=a*u(3);
else
if u(2)==0
u(1)=0;
else
if abs((u(1)-u(3))/u(3))>=1
u(1)=u(1)*u(3)/u(2);
end
end
end
sys=u(1);
end
function sys=malGetTimeOfNextVarHit(t,x,u)
sampleTime=1;
sys =t+sampleTime;
function sys=mdlTerminate(t,x,u)
sys=[]; |
|