scdxhy 发表于 2008-3-19 18:12

我也问一个关于sfunction 的问题,请高手指点!

这是我编的s函数,
function =system1(t,x,u,flag)
switch flag,
    case 0,
      =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 =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=;

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.
我实在找不出什么原因,请高手指教!
页: [1]
查看完整版本: 我也问一个关于sfunction 的问题,请高手指点!