|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
错误是:Output returned by S-function 'chap_1s' in block 'chap10_1/S-Function' during flag=3 call must be a real vector of length 1
S函数控制程序是:chap_1s.m
function[sys,x0,str,ts] = spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case{2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts] = 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 = [0 0];
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[sys,x0,str,ts] = spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=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[sys,x0,str,ts] = 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 = [0;0];
str = [];
ts = [0 0];
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);
模型如下:
[ 本帖最后由 xinyuxf 于 2007-5-4 19:42 编辑 ] |
|