ly012659 发表于 2007-10-15 13:19

s-函数出错求助

跟这段程序较劲好几天了,还是没有解决,哪位帮看看,指点一下迷津,感激涕零


switch flag,

case 0,
    =mdlInitializeSizes(u,lamata,theta0); %
case 2,
    sys=mdlUpdate(x,u,lamata);
case 3,
    sys=mdlOutputs(x);
case 4,
    sys=mdlGetTimeOfNextVarHit(t,x,u);
case {1,4,9}
      sys=[];
otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end

function =mdlInitializeSizes(u,lamata,theta0)

sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 36;
sizes.NumOutputs   = 1;
sizes.NumInputs      = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;   % at least one sample time is needed
sys = simsizes(sizes);

theta = theta0;
P = eye(4);
H = ';
K = P*H*(H'*P*H+lamata);
U = ';
Y = ';
E = ';
x0 = ;


ts= ;

function sys=mdlUpdate(x,u,lamata)
U = x(1:4);
Y = x(5:8);
E = x(9:12);
i = 4;
while i>1
    U(i) = U(i-1);%U(3) = U(2);U(2) = U(1);
    Y(i) = Y(i-1);%Y(3) = Y(2);Y(2) = Y(1);
    E(i) = E(i-1);%e(k-1)e(k-2)...e(k-4)
    i = i-1;
end
U(1) = u(1);
Y(1) = u(2);
E(1) = u(3)-u(2);

H = [-Y(1:2);U(2:3)];
P = ;
K = x(29:32);
theta = x(33:36);
if norm(K)<0.0001
   sys = x;
   return
else
   P = (1-K*H')*P/lamata;
   theta = theta + K*(Y(1)-H'*theta);
   K = P*H*(H'*P*H+lamata);
   sys = ;
   %sys = ;
end


function sys = mdlOutputs(x)
theta = x(33:36);
U = x(1:4);
E = x(9:12);
sys = pid(U,E,theta);

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 = [];


function y = pid(u,e,theta)
y = (e(1:3)'*)*0.194/theta(3)+u(1)+theta(4)/theta(3)*(u(2)-u(1));





上面的程序总是报错Output returned by S-function 'mys_fcn' in 'untitled1/Subsystem/S-Function' during flag=3 call must be a real vector of length 1,但是照理说这么算出来的输出应该为实数,不可能出现复数的啊,哪位能帮忙看一下,不胜感激!!

花如月 发表于 2007-10-15 16:37

回复 #1 ly012659 的帖子

不要照理说是什么样子,出错了自然不会按照常规了。根据提示看看出现的到底是什么数,并查找出现的原因

xhf0003 发表于 2007-10-21 14:43

sizes.DirFeedthrough = 0;改成1试试
页: [1]
查看完整版本: s-函数出错求助