我正在尝试使用Matlab S-Function构建跟踪器微分器。但是,它给了我一个错误说" 输出由S-function' han_td' in' ex_han / S-Function'在flag = 3期间,call必须是长度为2的实数向量"。
我无法看清我做错了什么。以下是代码:
function [sys,x0,str,ts]=han_td(t,x,u,flag,r,h,T)
switch flag,
case 0, [sys,x0,str,ts]=mdlInitializeSizes(T);
case 2, sys = mdlUpdates(x,u,r,h,T);
case 3, sys = x;
case {1, 4, 9}, sys = [];
otherwise, error(['Unhandled flag = ',num2str(flag)]);
end;
%initialization function mdlInitializeSizes
function [sys,x0,str,ts] = mdlInitializeSizes(T)
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 2;
sizes.NumOutputs = 2;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0;0];
str = [];
ts = [-1 0];
function sys = mdlUpdates(x,u,r,h,T)
sys=[x(1)+T*x(2); x(2)+T*fst2(x,u,r,h)];
function f=fst2(x,u,r,h)
delta =r*h;
delta0=delta*h;
y0=x(1)-u+h*x(2);
a0=sqrt(delta*delta+8*r*abs(y0));
if abs(y0)<=delta0, a=x(2)+y0/h;
else, a=x(2)+0.5*(a0-delta)*sign(y0); end
if abs(a)<=delta, f=-r*a/delta;
else, f=-r*sign(a);end