|
!'和の公式により回帰式を求める(修正指数関数)
LET N=12
OPTION BASE 0
DIM Y(N)
RANDOMIZE
LET A=RND*5
LET B=RND*5
LET C=INT(RND*100)+100
FOR I=0 TO N-1
LET Y(I)=C-B*A^I !'仮データ作成
NEXT I
FOR I=0 TO N-1
PRINT "X=";I;"Y=";Y(I);"^Y=";FORECAST(I,N,Y)
NEXT I
END
EXTERNAL FUNCTION FORECAST(X,N,YA())
!'Y=C-B*A^X 修正指数関数
!'S1=Y(0)+Y(1)+Y(2)+Y(3)+...Y(n-1)
!'S2=Y(n)+Y(n+1)+Y(n+2)+...Y(2n-1)
!'S3=Y(2n)+Y(2n+1)+Y(2n+2)+...Y(3n-1)
!'S1=(C-B)+(C-B*A)+(C-B*A^ 2)+(C-B*A^3)+...(C-B*A^(N-1))
!'S2=(C-B*A^N)+(C-B*A^(N+1))+...(C-B*A^(2*(N-1)))
!'S3=(C-B*A^(2*N))+(C-B*A^(2*N+2))+...(C-B*A^(3*(N-1)))
!'S1=N*C+B*(A^N-1)/(A-1)
!'S2=N*C+B*A^N*(A^N-1)/(A-1)
!'S3=N*C+B*A^(2*N)*(A^N-1)/(A-1)
LET NN=INT(N/3)
FOR I=0 TO NN-1
LET S1=S1+YA(I)
LET S2=S2+YA(NN+I)
LET S3=S3+YA(2*NN+I)
NEXT I
LET A=((S3-S2)/(S2-S1))^(1/NN)
LET B=(S1-S2)*(A-1)/(A^NN-1)^2
!'LET C=1/NN*(S1+B*(A^NN-1)/(A-1))
LET C=1/NN*((S1*S3-S2*S2)/(S1+S3-2*S2))
LET FORECAST =C-B*A^X
END FUNCTION
|
|