S函数问题求助
我要编写一个关于参数自整定的S函数function = para(t,x,u,flag)
global Ke Kec Ku;
Ke=18;Kec=1;Ku=0.5;
switch flag,
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {1,2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
function sys=mdlOutputs(t,x,u)
%u(1)和u(2)分别为偏差e和偏差变化率ec
%sys(1),sys(2),sys(3)分别为调整后的Ke,Kec,Ku
if abs(u(1))>0.5|abs(u(2))>0.3
sys(1)=0.2*Ke;sys(2)=0.3*Kec;sys(3)=Ku+0.5;
elseif abs(u(1))<0.2|abs(u(2))<0.1
sys(1)=0.5*Ke;sys(2)=0.5*Kec;sys(3)=Ku+0.1;
end
sys=[];
主要就是最后这个输出,我想输出调整后的Ke,Kec,Ku,如何设置sys=[]这里面呢?上面红色的地方的地方要如何修改?
有高手可以提示一下吗?谢谢! 看上去好像没什么问题,并不需要什么特别的设置
function = para(t,x,u,flag)
global Ke Kec Ku;
Ke=18;Kec=1;Ku=0.5;
switch flag,
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {1,2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0= [];
str=[];
ts=[-1 0];%这个要有的
function sys=mdlOutputs(t,x,u)
%u(1)和u(2)分别为偏差e和偏差变化率ec
%sys(1),sys(2),sys(3)分别为调整后的Ke,Kec,Ku
if abs(u(1))>0.5||abs(u(2))>0.3
sys(1)=0.2*Ke;sys(2)=0.3*Kec;sys(3)=Ku+0.5;
elseif abs(u(1))<0.2||abs(u(2))<0.1
sys(1)=0.5*Ke;sys(2)=0.5*Kec;sys(3)=Ku+0.1;
end
%sys=[];
也可以把Ke,Kec,Ku写在function里面
function = para(t,x,u,flag,Ke,Kec,Ku)
%global Ke Kec Ku;
%Ke=18;Kec=1;Ku=0.5;%这三个变量是输入量
switch flag,
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u,Ke,Kec,Ku);
case {1,2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates= 0;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0= [];
str=[];
ts=[-1 0];
function sys=mdlOutputs(t,x,u,Ke,Kec,Ku)
%u(1)和u(2)分别为偏差e和偏差变化率ec
%sys(1),sys(2),sys(3)分别为调整后的Ke,Kec,Ku
if abs(u(1))>0.5||abs(u(2))>0.3
sys(1)=0.2*Ke;sys(2)=0.3*Kec;sys(3)=Ku+0.5;
elseif abs(u(1))<0.2||abs(u(2))<0.1
sys(1)=0.5*Ke;sys(2)=0.5*Kec;sys(3)=Ku+0.1;
end
试一下看看吧 谢谢!我会试试
值得看看
正在使用s函数,来学习一下
页:
[1]