|
!' ブレント法(BRENT法)
PUBLIC NUMERIC T
INPUT PROMPT "X=":T
LET EPS=1E-8
LET A=1
LET B=T
LET C=A
LET FLG=0
DO UNTIL F(B)=0 OR F(S)=0 OR ABS(B-A)<EPS
IF F(A)<>F(C) AND F(B)<>F(C) THEN
LET S=A*F(B)*F(C)/(F(A)-F(B))/(F(A)-F(C))+B*F(A)*F(C)/(F(B)-F(A))/(F(B)-F(C))+C*F(A)*F(B)/(F(C)-F(A))/(F(C)-F(B))
ELSE
LET S=B-F(B)*(B-A)/(F(B)-F(A))
END IF
IF (S<(3*A+B)/4 OR S>B) OR (FLG=1 AND ABS(S-B)>=ABS(B-C)/2) OR (FLG=0 AND ABS(S-B)>=ABS(C-D)/2) OR (FLG=1 AND ABS(B-C)<EPS) OR (FLG=0 AND ABS(C-D)<EPS) THEN
LET S=(A+B)/2
LET FLG=1
ELSE
LET FLG=0
END IF
LET D=C
LET C=B
IF F(A)*F(S)<0 THEN LET B=S ELSE LET A=S
IF ABS(F(A))<ABS(F(B)) THEN SWAP A,B
PRINT B;S
LOOP
PRINT B;S;B*B*B;S*S*S
END
EXTERNAL FUNCTION F(X)
LET F=X*X*X-T
END FUNCTION
|
|