马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
这是我编的s函数,
function [sys,x0,str,ts]=system1(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(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=3;
sizes.NumDiscStates=0;
sizes.NumOutputs=1;
sizes.NumInputs=1;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
sys=simsizes(sizes);
x0=[1;
1;
1];
str=[];
ts=[0,0];
function sys=mdlDerivatives(t,x,u)
dx(1)=-u*x(2)+x(3);
dx(2)=(u*u-1)*x(2)+u*x(3);
dx(3)=-x(3)+x(1)*x(1)+0.5;
sys=dx;
function sys=mdlUpdate(t,x,u)
sys=[];
function sys=mdlOutputs(t,x,u)
sys=x(1);
function sys=mdlTerminate(t,x,u)
sys=[];
命令窗口老是有警告:
Warning: Unable to reduce the step size without violating minimum step size of 0.01 at time 2.805106062496166. Continuing simulation with the step size restricted to 0.01 and using an effective relative error tolerance of 2.569641885883541e+040, which is greater than the specified relative error tolerance of 0.001.
还提示sfunction有问题,说是State derivatives returned by S-function 'system1' in 'fz/S-Function' during flag=1 call must be a real vector of length 3.
我实在找不出什么原因,请高手指教! |