多倍長黄金比を求める

 投稿者:しばっち  投稿日:2010年 1月23日(土)19時24分40秒
  多倍長黄金比を求める (SQR(5)+1)/2=1.618033...

計算式に

    (1-X)^(-.5)=1+(1/2)*X+(1*3)/(2*4)*X^2+(1*3*5)/(2*4*6)*X^3+...

を使用し、以下の関係式

    SQR(5)= 6460 / 2889 * (1 - 1 / 8346321)^(-.5)

を使って黄金比を求める。

PUBLIC NUMERIC KETA,EPS,SIGN
INPUT  PROMPT "桁数=":KETA
LET KETA=INT(KETA/4)
LET EPS=2
LET BIAS=0
LET KETA=KETA+EPS
LET SIGN=-BIAS-1
DIM A(-BIAS-1 TO KETA),S(-BIAS-1 TO KETA),T(-BIAS-1 TO KETA)
LET A(0)=1
LET S(0)=1
LET N=1
DO
   MAT A=(2*N-1)*A
   FOR I = 0 TO KETA - 1
      LET  R = A(I) - INT(A(I)/16692642/N)*(16692642*N)
      LET  A(I) = INT(A(I) /16692642/N)
      LET  A(I + 1) = A(I + 1) + R * 10000
   NEXT I
   LET  A(KETA) = INT(A(KETA)/16692642/N)
   MAT S=S+A
   FOR I = KETA TO 0 STEP -1
      IF S(I) >= 10000 THEN
         LET  R = INT(S(I) / 10000)
         LET  S(I) = S(I) - R * 10000
         LET  S(I-1) = S(I-1) + R
      END IF
   NEXT I
   LET FL=0
   FOR I=0 TO KETA
      IF S(I)<>T(I) THEN
         LET T(I)=S(I)
         LET FL=1
         LET N=N+1
         EXIT FOR
      END IF
   NEXT I
   IF FL=0 THEN EXIT DO
LOOP
MAT S=6460*S
FOR I = KETA TO 0 STEP -1
   IF S(I) >= 10000 THEN
      LET  R = INT(S(I) / 10000)
      LET  S(I) = S(I) - R * 10000
      LET  S(I-1) = S(I-1) + R
   END IF
NEXT I
FOR I = 0 TO KETA - 1
   LET  R = S(I) - INT(S(I)/2889)*2889
   LET  S(I) = INT(S(I)/2889)
   LET  S(I + 1) = S(I + 1) + R * 10000
NEXT I
LET  S(KETA) = INT(S(KETA)/2889)
LET S(0)=S(0)+1
FOR I = 0 TO KETA - 1
   LET  R = S(I) - INT(S(I)/2)*2
   LET  S(I) = INT(S(I)/2)
   LET  S(I + 1) = S(I + 1) + R * 10000
NEXT I
LET  S(KETA) = INT(S(KETA)/2)
CALL DISPLAY(S)
END

EXTERNAL  SUB DISPLAY(X())
FOR K=-BIAS TO 0
   IF X(K)<>0 THEN EXIT FOR
NEXT K
IF K > 0 THEN LET K=0
IF X(SIGN) = -1 THEN PRINT "- ";
PRINT STR$(X(K));" ";
IF K=0 THEN PRINT "."
FOR I=K+1 TO KETA-EPS
   LET L=L+1
   PRINT RIGHT$("000"&STR$(X(I)),4);" ";
   IF I=0 THEN
      PRINT "."
      LET L=0
   END IF
   IF MOD(L,25)=0 THEN PRINT
NEXT I
PRINT
END SUB
 

戻る