马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
function [sys,x0,str,ts] = shit(t,x,u,flag,p,omega)
k1=1325200;
m1=3.18;
m2=0.29;
c=62.86;
k2=38000;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u,p,omega,m1,m2,k2,k1,c);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 4;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = zeros(4,1);
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u,p,omega,m1,m2,k2,k1,c)
x1dot=x(2);
x2dot= p*exp(j*t*omega)/m1-c/m1*(x(2)-x(4))-k2*(x(1)-x(3))/m1;
x3dot=x(3);
x4dot=c/m2*(x(2)-x(4))+k2/m2*(x(1)-x(3));
sys=[x1dot,x2dot,x3dot,x4dot]
end
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u)
sys = x(1);
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];
% end mdlTerminate
end
利用这个模型仿真后出现State derivatives returned by S-function 'shit' in block 'shit1/S-Function' during flag=1 call must be a real vector of length 4这样的错误,请大家看看怎么改啊? |