灰色预测程序
程序员文章站
2022-07-14 14:25:58
...
- 结果图
- 源码
function pre_data = Gray_Prediction(data, m)
%{
函数功能:灰色预测;
输入:
data:参考数据,一行;
m:预测点数;
输出:
pre_data:预测数据;
示例:
clear; clc;
% data = [89677, 99215, 109655, 120333, 135823, 159878, 182321, 209407, 246619, 300670];
% data = [174, 179, 183, 189, 207, 234, 220.5, 256, 270, 285];
m = 2;
t1 = 1 : length(data);
t2 = 1 : m + length(data);
pre_data = Grey_Prediction(data, m);
plot(t1, data, 'o', t2, pre_data, 'linewidth', 2)
%}
% = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
if nargin < 2
error('输入参数不足!');
end
% 原始数据累加
csum_data = cumsum(data);
n = length(data);
csum_at = zeros(1, n - 1);
for i = 1 : n - 1
csum_at(i) = (csum_data(i) + csum_data(i + 1))/2; % 生成累加矩阵
end
% 计算待定参数的值
D = data(2 : end)';
E = [- csum_at; ones(1, n - 1)];
c = (E*E')\E*D;
a = c(1);
b = c(2);
% 预测后续数据
pre = zeros(1, n + m);
pre(1) = data(1);
for i = 2 : n + m
pre(i) = (data(1) - b/a)/exp(a*(i - 1)) + b/a ;
end
% 计算预测数据
pre_data = zeros(1, n + m);
pre_data(1) = data(1);
for i = 2 : n + m
pre_data(i) = pre(i) - pre(i - 1);
end
上一篇: 北京市房价预测---数据收集
下一篇: 生物碱基序列分形绘图