跪求s函数编的灰色预测模块
各位大虾谁能帮忙。我需要用simulink 中的s函数编写灰色预测模块,我编写的程序总是不理想,且和模糊控制结合时无法预测,谁能帮帮我这可怜的孩子啊,不胜感激啊!!!!!!!
function [sys,x0,str,ts] = try_3(t,x,u,flag)
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 = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [-1 0];
set_param(gcb,'UserData',[0 0 0] );
function sys=mdlOutputs(t,x,u)
g=get_param(gcb,'UserData');
c=u
Y=[g u];
Ym= [Y(2) Y(3) Y(4)];
set_param(gcb,'UserData',Ym);
y1=Y(1);
y2=Y(1)+Y(2);
y3=y2+Y(3);
y4=y3+Y(4);
B=[-0.5*(y1+y2),1;-0.5*(y2+y3),1;-0.5*(y3+y4),1];
N=B'*B;
if det(N)==0;
a=0;
else
C=(inv(B'*B));
E=C*B';
D=E*[Y(2) Y(3) Y(4)]';
m = (y1-D(2)/D(1))*exp(-D(1)*4)+D(2)/D(1);
n=(y1-D(2)/D(1))*exp(-D(1)*3)+D(2)/D(1);
a=m-n;
end
sys=a;
这是我编的程序,谁能帮忙瞅瞅啊!