用MATLAB中S函数仿真模型参考自适应遇到的问题
我在做感应电机参数辨识,采取模型参考自适应的方法,采用参数误差逼近的方法.用S函数编写控制模型时,遇到一些问题,我的程序如下:function = ac_model(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(x0);
sizes = simsizes;
sizes.NumContStates= 7;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 7;
sizes.NumInputs = 10;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0= ;
str = [];
ts= ;
function sys=mdlDerivatives(t,x,u)
g1=100;g2=500;g3=500;g4=10;g5=10;k=100;
dx(1)=x(3)*u(1)-u(5)*u(2)+x(4)*u(7)+x(5)*u(9)+x(6)*u(5)*u(8)+x(7)*(u(5)*(u(10)+u(3)))-k*u(6);
dx(2)=x(3)*u(2)+u(5)*u(1)+x(4)*u(7)+x(5)*u(10)-x(6)*u(5)*u(7)+x(7)*(u(4)-u(5)*u(9));
dx(3)=-g1*u(6)*u(1);
dx(4)=-g2*u(6)*u(7);
dx(5)=-g3*u(6)*u(9);
dx(6)=-g4*u(6)*u(5)*u(8);
dx(7)=-g5*u(6)*(u(5)*u(10)+u(3));
sys=dx;
function sys=mdlOutput(t,x,u)
tspan=;
options=odeset('RelTol',1e-3,'AbsTol',1e-3);
=ode45('ac_model',tspan,x0,options);
if abs(u(6))>1e-8
sys=[];
else
sys = ;
end
老是出现 flag = 3 (output), at time 0. MATLAB error message:
Undefined function or variable 'mdlOutputs'为什么呢?
望不舍赐教,谢谢 你定义的是mdlOutput
但你上面用的是mdlOutputs
如红笔所示
function = ac_model(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(x0);
sizes = simsizes;
sizes.NumContStates= 7;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 7;
sizes.NumInputs = 10;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0= ;
str = [];
ts= ;
function sys=mdlDerivatives(t,x,u)
g1=100;g2=500;g3=500;g4=10;g5=10;k=100;
dx(1)=x(3)*u(1)-u(5)*u(2)+x(4)*u(7)+x(5)*u(9)+x(6)*u(5)*u(8)+x(7)*(u(5)*(u(10)+u(3)))-k*u(6);
dx(2)=x(3)*u(2)+u(5)*u(1)+x(4)*u(7)+x(5)*u(10)-x(6)*u(5)*u(7)+x(7)*(u(4)-u(5)*u(9));
dx(3)=-g1*u(6)*u(1);
dx(4)=-g2*u(6)*u(7);
dx(5)=-g3*u(6)*u(9);
dx(6)=-g4*u(6)*u(5)*u(8);
dx(7)=-g5*u(6)*(u(5)*u(10)+u(3));
sys=dx;
function sys=mdlOutput(t,x,u)
tspan=;
options=odeset('RelTol',1e-3,'AbsTol',1e-3);
=ode45('ac_model',tspan,x0,options);
if abs(u(6))>1e-8
sys=[];
else
sys = ;
end 细心呀~~
页:
[1]