|
!'和の公式より回帰式を求める(ゴンペルツ)
OPTION BASE 0
LET N =12
DIM Y(N)
RANDOMIZE
LET K=INT(RND*5)+5
LET A=RND
LET B=RND
FOR I=0 TO N-1
LET Y(I)=K*A^(B^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=K*A^(B^X) ゴンペルツ (条件 0<A<1,0<B<1)
LET NN=INT(N/3)
FOR I=0 TO NN-1
LET S1=S1+LOG(YA(I))
LET S2=S2+LOG(YA(NN+I))
LET S3=S3+LOG(YA(2*NN+I))
NEXT I
LET B=((S3-S2)/(S2-S1))^(1/NN)
LET AA=(S2-S1)*(B-1)/(B^NN-1)^2
LET KK=1/NN*((S1*S3-S2*S2)/(S1+S3-2*S2))
LET K=EXP(KK)
LET A=EXP(AA)
LET FORECAST =K*A^(B^X)
END FUNCTION
|
|