Matlab的灰色预测程序:y=input('请输入数据');n=length(y);yy=ones(n,1);yy(1)=y(1);fori=2:nyy(i)=yy(i-1)+y(i)endB=ones(n-1,2);fori=1:(n-1)B(i,1)=-(yy(i)+yy(i+1))/2;B(i,2)=1;endBT=B';forj=1:(n-1)YN(j)=y(j+1);endYN=YN';A=inv(BT*B)*BT*YN;a=A(1);u=A(2);t=u/a;t_test=input('输入需要预测的个数');i=1:t_test+n;yys(i+1)=(y(1)-t).*exp(-a.*i)+t;yys(1)=y(1);forj=n+t_test:-1:2ys(j)=yys(j)-yys(j-1);endx=1:n;xs=2:n+t_test;yn=ys(2:n+t_test);plot(x,y,'^r',xs,yn,'*-b');det=0;fori=2:ndet=det+abs(yn(i)-y(i));enddet=det/(n-1);disp(['百分绝对误差为:',num2str(det),'%']);disp(['预测值为:',num2str(ys(n+1:n+t_test))]);请输入数据[29.830.1141.0570.1277.7977.79104.8265.2282.7100.79]输入需要预测的个数4百分绝对误差为:14.5128%预测值为:110.5718120.8171132.0116144.2434