求助:老问题Undefined function or variable 't'
我编的一个s函数中,在指向machine.m 文件时,弹出对话框 Error in '' while executing M-files S-function 'machine', flag = 0(initialize), at start ofsimulation. MATLAB error message: Undefined function or variable 't'.我这个s函数里面没有用到变量't'啊,而且这个t是s函数里面function =machine(t,x,u,flag,p,Rs,Rr,Ls,Lr,Lm,J,w1)自带的呀
我也搜索了其它帖子,还有置顶帖,小弟不才,还是没有搞定。下面是整个s函数,麻烦帮我看看。。非常感谢~
%S-function for continuous state equation
function =machine(t,x,u,flag,p,Rs,Rr,Ls,Lr,Lm,J,w1)
%定义参数吧
p=2;Rs= 0.435; Rr=0.816 ; Ls=71.31;Lr=71.31; Lm=69.31; J=0.089; w1=120*pi;
switch flag,
%Initialization
case 0,
=mdlInitializeSizes(p,Rs,Rr,Ls,Lr,Lm,J,w1);
case 1
sys=mdlDerivatives(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
%Outputs
case 3,
sys=mdlOutputs(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
%Unhandled flags
case {2, 4, 9 }
sys = [];
%Unexpected flags
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
%mdlInitializeSizes
function =mdlInitializeSizes(p,Rs,Rr,Ls,Lr,Lm,J,w1)
sizes = simsizes;
sizes.NumContStates= 5;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 6;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys=simsizes(sizes);
x0=;
str=[];
ts=;
sys=mdlDerivatives(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
% x=;u=;
Ll=Ls*Lr-Lm^2;
bn=1.5*p^2*Lm*Ll/J;
A=1/Ll*[-Rs*Lr w1*Ll+x(5)*Lm^2 Rr*Lm x(5)*Lr*Lm 0;
-w1*Ll-x(5)*Lm^2 -Rs*Lr -x(5)*Lr*Lm Rr*Lm 0;
Rs*Lm -x(5)*Ls*Lm -Rs*Lr w1*Ll-x(5)*Ls*Lr 0;
x(5)*Ls*Lm Rs*Lr -w1*Ll+x(5)*Ls*Lr -Rs*Lr 0;
-bn*x(4) bn*x(3) 0 0 0; ]
B=1/Ll*[Lr 0-Lm 0 0;
0Lr0-Lm 0
-Lm 0 Ls 0 0
0 -Lm 0 Ls 0
0 0 0 0 -p*Ll/J]
sys=A*x(1:5)+B*u;
% R=;
% sys=-L*R*x+L*U;
function sys=mdlOutputs(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1)
x(6)=1.5*p*Lm*(x(3)*x(2)-x(1)*x(4));
sys=x;
% sys(1)=u(1);
% sys(2)=x(1);
% sys(3)=u(2);
% sys(4)=x(2);
% sys(5)=1.5*Pn*Lm*(x(2)*x(3)-x(1)*x(4)); 初始化肯定要有时间 这些函数不要改动
页:
[1]