Grey prediction model and its code

Grey forecasting model is a method of establishing mathematical models and making predictions through a small amount of incomplete information, and is suitable for dealing with small sample forecasting problems.

clear
syms a b;
c=[a b]';
A=[89677,99215,109655,120333,135823,159878,182321,209407,246619,300670];% 原始数据矩阵
B=cumsum(A);  % 原始数据累加
n=length(A);
for i=1:(n-1)
    C(i)=(B(i)+B(i+1))/2;  % 生成累加矩阵
end
% 计算待定参数的值
D=A;D(1)=[];
D=D';
E=[-C;ones(1,n-1)];
c=inv(E*E')*E*D;
c=c';
a=c(1);b=c(2);
% 预测后续数据
F=[];F(1)=A(1);
for i=2:(n+10)
    F(i)=(A(1)-b/a)/exp(a*(i-1))+b/a ;
end
G=[];G(1)=A(1);
for i=2:(n+10)
    G(i)=F(i)-F(i-1); %得到预测出来的数据
end 

G % 展示预测数据
plot(1999:2008,A,'o',1999:2018,G)  %原始数据与预测数据的比较
xlabel('年份')
ylabel('利润')

Guess you like

Origin blog.csdn.net/DwenKing/article/details/108172078