灰色模型预测GM(1,1)与线性回归预测(一元、多元)新建一个工程,添加一个模块(.bas),两个命令按钮:窗体代码:OptionExplicitPrivateSubCommand1_Click()'灰色模型预测DimDataAsStringData=2.67,3.13,3.25,3.36,3.56,3.72GM1_1_PredictDataEndSubPrivateSubCommand2_Click()'线性回归预测DimX1AsString,X2AsString,X3AsString,X4AsString,YAsStringX1=100.38,99.7,92.3,87.6,87.17,88.3,92.75,100.6,90.05;'最后要加上分号;X2=53.24,51.5,50.5,52.4,59.6,59.7,65.2,62.4,53.68;'最后要加上分号;X3=226,250,281,272,194,180,105,115,250;'最后要加上分号;Y=644,640,517,425,385,401,448,599,462'最后不要加上分号;请注意!!!Linear_Regression_PredictX1&X2&X3&YEndSub模块代码:OptionExplicitPrivateSubCalculate_1_AGO(X_0()AsDouble,X_1()AsDouble)'做一次累加生成1-AGODimiAsLong,TempXAsDouble,KAsLongK=UBound(X_0)ReDimX_1(K)Fori=0ToKTempX=TempX+X_0(i)X_1(i)=TempXNextiEndSubPrivateSubCalculate_Matrix_B(X_1()AsDouble,B()AsDouble)'计算数据矩阵BDimiAsLong,KAsLongK=UBound(X_1)-1ReDimB(K,1)Fori=0ToKB(i,0)=-0.5*(X_1(i)+X_1(i+1))B(i,1)=1NextiEndSubPrivateSubCalculate_Matrix_YN(X_0()AsDouble,YN()AsDouble)'计算数据矩阵YNDimiAsLong,KAsLongK=UBound(X_0)-1ReDimYN(K,0)Fori=0ToKYN(i,0)=X_0(i+1)NextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Transpotation'功能:计算矩阵的转置transpotation'参数:m-Integer型变量,矩阵的行数'n-Integer型变量,矩阵的列数'mtxA-Double型mxn二维数组,存放原矩阵'mtxAT-Double型nxm二维数组,返回转置矩阵''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateSubMatrix_Transpotation(mtxA()AsDouble,mtxAT()AsDouble)DimiAsInteger,jAsIntegerDimMAsInteger,NAsIntegerM=UBound(mtxA,2)N=UBound(mtxA,1)ReDimmtxAT(M,N)Fori=0ToMForj=0ToNmtxAT(i,j)=mtxA(j,i)NextjNextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Multiplication'功能:计算矩阵的乘法multiplication'参数:m-Integer型变量,相乘的左边矩阵的行数'n-Integer型变量,相乘的左边矩阵的列数和右边矩阵的行数'l-Integer型变量,相乘的右边矩阵的列数'mtxA-Double型mxn二维数组,存放相乘的左边矩阵'mtxB-Double型nxl二维数组,存放相乘的右边矩阵'mtxC-Double型mxl二维数组,返回矩阵乘积矩阵''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateSubMatrix_Multiplication(mtxA()AsDouble,mtxB()AsDouble,mtxC()AsDouble)DimiAsInteger,jAsInteger,KAsIntegerDimMAsInteger,NAsInteger,LAsIntegerM=UBound(mtxA,1):N=UBound(mtxB,1):L=UBound(mtxB,2)ReDimmtxC(M,L)Fori=0ToMForj=0ToLmtxC(i,j)=0#ForK=0ToNmtxC(i,j)=mtxC(i,j)+mtxA(i,K)*mtxB(K,j)NextKNextjNextiEndSub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''函数名:Matrix_Inversion'功能:矩阵求逆'参数:n-Integer型变量,矩阵的阶数'mtxA-Double型二维数组,体积为nxn。存放原矩阵A;返回时存放其逆矩阵A-1。'返回值:Boolean型,失败为False,成功为True''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PrivateFunctionMatrix_Inversion(mtxA()AsDouble)AsBoolean'局部变量DimNAsIntegerN=UBound(mtxA)ReDimnIs(N)AsInteger,nJs(N)AsIntegerDimiAsInteger,jAsInteger,KAsIntegerDimdAsDouble,PAsDouble'全选主元,消元ForK=0ToNd=0#Fori=KToNForj=KToNP=Abs(mtxA(i,j))If(Pd)Thend=PnIs(K)=inJs(K)=jEndIfNextjNexti'求解失败If(d+1#=1#)ThenMatrix_Inversion=FalseExitFunctionEndIfIf(nIs(K)K)ThenForj=0ToNP=mtxA(K,j)mtxA(K,j)=mtxA(nIs(K),j)mtxA(nIs(K),j)=PNextjEndIfIf(nJs(K)K)ThenFori=0ToNP=mtxA(i,K)mtxA(i,K)=mtxA(i,nJs(K))mtxA(i,nJs(K))=PNextiEndIfmtxA(K,K)=1#/mtxA(K,K)Forj=0ToNIf(jK)ThenmtxA(K,j)=mtxA(K,j)*mtxA(K,K)NextjFori=0ToNIf(iK)ThenForj=0ToNIf(jK)ThenmtxA(i,j)=mtxA(i,j)-mtxA(i,K)*mtxA(K,j)NextjEndIfNextiFori=0ToNIf(iK)ThenmtxA(i,K)=-mtxA(i,K)*mtxA(K,K)NextiNextK'调整恢复行列次序ForK=NTo0Step-1If(nJs(K)K)ThenForj=0ToNP=mtxA(K,j)mtxA(K,j)=mtxA(nJs(K),j)mtxA(nJs(K),j)=PNextjEndIfIf(nIs(K)K)ThenFori=0ToNP=mtxA(i,K)mtxA(i,K)=mtxA(i,nIs(K))mtxA(i,nIs(K))=PNextiEndIfNextK'求解成功Matrix_Inversion=TrueEndFunctionPrivateSubPredicted_Value(ByValX_1_0AsDouble,ByValu_valueAsDouble,ByVala_valueAsDouble,KAsLong,PV()AsDouble)DimiAsLongReDimPV(K)Fori=1ToK+1PV(i-1)=(X_1_0-u_value/a_value)*Exp(-a_value*(i-1))*(1-Exp(a_value))NextiPV(0)=X_1_0EndSubPrivateSubString_to_Array(DataAsString,X_0()AsDouble)'Data字符串转为X_0数组,X_0是原始序列DimPredict_Data()AsString,KAsLong,iAsLongPredict_Data=Split(Data,,)K=UBound(Predict_Data)ReDimX