马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
找到的异步电机仿真程序运行之后显示有错误:Error in 'dianjizhuanjukongzhi/S-Function' while executing M-File S-function 'model_motor', flag = 1 (derivatives), at time 0. MATLAB error message:
Undefined function or variable 'A'
求高手指点!
程序如下:
function [sys,x0,str,ts] = model_motor(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
Rs=0.687;Rr=0.642;Ls=0.084;Lr=0.852;Lm=0.813;w=1400;np=2;J=0.3;D=0.01;
A=1/(Ls*Lr-Lm^2)*[-Rs*Lr,w*Lm^2,Rr*Lm,w*Lm*Lr;-w*Lm^2,-Rs*Lr,-w*Lm*Lr,Rr*Lm;Rs*Lm,-w*Lm*Ls,-Rr*Ls,-w*Lr*Ls;w*Lm*Ls,Rs*Lm,w*Ls*Lr,-Rr*Ls];
B=1/(Ls*Lr-Lm^2)*[Lr,0;0,Lr;-Lm,0;0,-Lm];
C=[1,0,0,0;0,1,0,0];
D=zeros(2,2);
sizes = simsizes;
sizes.NumContStates = 5;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 6;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0 = [1.800,6.530,-2.350,-0.970,600];
str = [];
ts = [0 0];
function sys=mdlDerivatives(t,x,u)
sys(1:4)=A*X(1:4)+B*U(1:2);
Te=np*Lm*(X(2)*X(3)-X(4)*X(1));
w=X(5);
sys(5)=((Te-U(3))*np-D*X(5))/J;;
function sys=mdlUpdate(t,x,u)
sys=[];
function sys=mdlOutputs(t,x,u)
sys(1:2) = X(1:2);
sys(3)=Ls*X(1)+Lm*X(3);
sys(4)=Ls*X(2)+Lm*X(4);
sys(5)=X(5);
sys(6)=np*Lm*(X(2)*X(3)-X(1)*X(4));
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 = [];
|