您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 其它文档 > 灰色模型预测GM(1-1)MATLAB程序代码
版权所有引用请注明出处functiongmcal=gm1(x)%%二次拟合预测GM(1,1)模型%x=[5999,5903,5848,5700,7884];sizexd2=size(x,2);%求数组长度k=0;fory1=xk=k+1;ifk1x1(k)=x1(k-1)+x(k);%累加生成z1(k-1)=-0.5*(x1(k)+x1(k-1));%z1维数减1,用于计算Byn1(k-1)=x(k);elsex1(k)=x(k);endend%x1,z1,k,yn1sizez1=size(z1,2);%size(yn1);z2=z1';z3=ones(1,sizez1)';YN=yn1';%转置B=[z2z3];au0=inv(B'*B)*B'*YN;au=au0';afor=au(1);ufor=au(2);ua=au(2)./au(1);constant1=x(1)-ua;afor1=-afor;x1t1='x1(t+1)';estr='exp';tstr='t';leftbra='(';rightbra=')';strcat(x1t1,'=',num2str(constant1),estr,leftbra,num2str(afor1),tstr,rightbra,'+',leftbra,num2str(ua),rightbra)%输出时间响应方程k2=0;fory2=x1k2=k2+1;ifk2kelseze1(k2)=exp(-(k2-1)*afor);endendsizeze1=size(ze1,2);z4=ones(1,sizeze1)';G=[ze1'z4];X1=x1';au20=inv(G'*G)*G'*X1;au2=au20';Aval=au2(1);Bval=au2(2);strcat(x1t1,'=',num2str(Aval),estr,leftbra,num2str(afor1),tstr,rightbra,'+',leftbra,num2str(Bval),rightbra)%输出时间响应方程nfinal=sizexd2-1+1;%决定预测的步骤数5这个步骤可以通过函数传入%nfinal=sizexd2-1+1;%预测的步骤数1fork3=1:nfinalx3fcast(k3)=constant1*exp(afor1*k3)+ua;end%一次拟合累加值fork31=nfinal:-1:0ifk311x31fcast(k31+1)=x3fcast(k31)-x3fcast(k31-1);elseifk310x31fcast(k31+1)=x3fcast(k31)-x(1);elsex31fcast(k31+1)=x(1);endendendx31fcast%一次拟合预测值fork4=1:nfinalx4fcast(k4)=Aval*exp(afor1*k4)+Bval;end%x4fcastfork41=nfinal:-1:0ifk411x41fcast(k41+1)=x4fcast(k41)-x4fcast(k41-1);elseifk410x41fcast(k41+1)=x4fcast(k41)-x(1);elsex41fcast(k41+1)=x(1);endendendx41fcast,x%二次拟合预测值%***精度检验pC************//////////////////////////////////k5=0;fory5=xk5=k5+1;ifk5sizexd2elseerr1(k5)=x(k5)-x41fcast(k5);endend%err1%绝对误差xavg=mean(x);%xavg%x平均值err1avg=mean(err1);%err1avg%err1平均值k5=0;s1total=0;fory5=xk5=k5+1;ifk5sizexd2elses1total=s1total+(x(k5)-xavg)^2;endends1suqare=s1total./sizexd2;s1sqrt=sqrt(s1suqare);%s1suqare,s1sqrt%s1suqare残差数列x的方差s1sqrt为x方差的平方根S1k5=0;s2total=0;fory5=xk5=k5+1;ifk5sizexd2elses2total=s2total+(err1(k5)-err1avg)^2;endends2suqare=s2total./sizexd2;%s2suqare残差数列err1的方差S2Cval=sqrt(s2suqare./s1suqare);Cval%nnn=0.6745*s1sqrt%CvalC检验值k5=0;pnum=0;fory5=xk5=k5+1;ifabs(err1(k5)-err1avg)0.6745*s1sqrtpnum=pnum+1;%ppp=abs(err1(k5)-err1avg)elseendendpval=pnum./sizexd2;pval%p检验值%arr1=x41fcast(1:6)%预测结果为区间范围预测步长和数据长度可调整程序参数进行改进
本文标题:灰色模型预测GM(1-1)MATLAB程序代码
链接地址:https://www.777doc.com/doc-3965077 .html