|
看上去好像没什么问题,并不需要什么特别的设置
function [sys,x0,str,ts] = para(t,x,u,flag)
global Ke Kec Ku;
Ke=18;Kec=1;Ku=0.5;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {1,2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=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 [sys,x0,str,ts] = para(t,x,u,flag,Ke,Kec,Ku)
%global Ke Kec Ku;
%Ke=18;Kec=1;Ku=0.5; %这三个变量是输入量
switch flag,
case 0,
[sys,x0,str,ts]=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 [sys,x0,str,ts]=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
试一下看看吧 |
|