伊米亚和 发表于 2011-5-3 17:23

异步电机仿真程序,有错误,求指点!

找到的异步电机仿真程序运行之后显示有错误: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 = model_motor(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
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)*;
C=;
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= ;
str = [];
ts= ;
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 = [];

樊增斌 发表于 2013-5-6 13:36

我也有同上的问题啊啊
页: [1]
查看完整版本: 异步电机仿真程序,有错误,求指点!