小弟请教一个关于S函数的问题
错误是:Output returned by S-function 'chap_1s' in block 'chap10_1/S-Function' during flag=3 call must be a real vector of length 1S函数控制程序是:chap_1s.m
function = spacemodel(t,x,u,flag)
switch flag,
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case{2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function = mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes =1; % At least one sample time is needed
sys = simsizes(sizes);
x0 = [];
str = [];
ts = ;
function sys=mdlOutputs(t,x,u)
g=9.8;
m=1;
l=0.25;
d=2.0;
a=20.0;b=15.0;
I=4/3*m*l^2;
A=1.0;F=1.0;
r=u(1);
x1=u(2);
x2=u(3);
dr=A*F*2*pi*cos(F*2*pi*t);
ddr=-A*(F*2*pi)^2*sin(2*pi*t);
e=x1-r;
de=x2-dr;
tol=(d-a*I)*de-b*I*e+I*ddr+d*dr+m*g*l*cos(x1);
sys(1)=tol;
S函数被控制程序是:chap_1plant.m
function = spacemodel(t,x,u,flag)
switch flag,
case 0,
=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case{2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function = mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates =2;
sizes.NumDiscStates =0;
sizes.NumOutputs =2;
sizes.NumInputs =1;
sizes.DirFeedthrough =0;
sizes.NumSampleTimes =1;
sys = simsizes(sizes);
x0 = ;
str = [];
ts = ;
function sys=mdlDerivatives(t,x,u)
g=9.8;
m=1;
l=0.25;
d=2.0;
I=4/3*m*l^2;
tol=u;
sys(1)=x(2);
sys(2)=1/I*(-d*x(2)-m*g*l*cos(x(1))+tol);
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
sys(2)=x(2);
模型如下:
希望懂这方面的高手指点一下!!
希望有高手指点一下!!性命攸关!!!:'( 把sizes.DirFeedthrough = 0改为1试试看
页:
[1]