马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
A=[276,-206,60,101,-95,111,-322,150,-162,-298,7,8,-68,452,-129,304,87,149,-223,-251,-102,-245,-17,169,159,103];
x0=[1995.2,2077,2030.1,2029.7,2242.7,2089.8,2043.9,2198.3,2084.9,2162.7,2198,2121.6,2390,2222.4,2408.6,2366.7,2218.4,2250.2,1881,2115.1,2017,2126.6,2212.1,2101.8,2228.2;
143.6,141.1,166.4,209.4,115.5,262.4,184.6,90.7,115.7,261.2,153.5,101.6,134.3,239.8,57.7,76.1,161.9,148.1,138.5,229.6,124.2,115.4,165.9,139.8,159.8;
1016.6,1340.6,1292.6,1478.4,1466.8,1275.7,1328.4,1449,1350.1,1313.6,1374.2,1452.8,1361.9,1089.9,1245.5,1510.7,1197,1236.8,1005.7,1344.5,1134.1,1195.7,1071.9,1029.6,1339.5;
285.9,350.6,294.5,311.6,345.7,295.7,251.2,331.7,293.8,335.1,288.6,245.2,297.6,333.6,319.8,322,308.1,324,299,323.5,319.2,298.5,288.4,295.4,296.8;];
[n,m]=size(x0);
AGO=cumsum(A);
T=1;
x1=zeros(n,m+T);
for k=1:(m-1)
Z(k)=(AGO(k)+AGO(k+1))/2; %Z(i)为xi(1)的紧邻均值生成序列
end
for i=1:n
for j=1:m
for k=1:j
x1(i,j)=x1(i,j)+x0(i,k);%原始数据一次累加,得到xi(1)
end
end
end
x11=x1(:,1:m);
X=x1(:,2:m)';%截取矩阵
Yn =A;%Yn为常数项向量
Yn(1)=[]; %从第二个数开始,即x(2),x(3)...
Yn=Yn';
%Yn=A(:,2:m)';
B=[-Z',X];
C=((B'.*B)\(B'.*Yn))';%由公式建立GM(1,n)模型
a=C(1);
b=C(:,2:n+1);
F=[];
F(1)=A(1);
u=zeros(1,m);
for i=1:m
for j=1:n
u(i)=u(i)+(b(j)*x11(j,i));
end
end
for k=2:m
F(k)=(A(1)-u(k-1)/a)/exp(a*(k-1))+u(k-1)/a;
end
G=[];
G(1)=A(1);
for k=2:m
G(k)=F(k)-F(k-1);%两者做差还原原序列,得到预测数据
end
t1=1:m;
t2=1:m;
plot(t1,A,'bo--');
hold on;
plot(t2,G,'r*-');
title('小麦预测结果');
legend('真实值','预测值');
这个是代码,
然后出来的结果错误,提示是矩阵维度必须一致,出错 GM1n (line 28)
C=((B'.*B)\(B'.*Yn))';%由公式建立GM(1,n)模型
这个怎么解决 |