|
!' 拡張ニュートン法
OPTION ARITHMETIC DECIMAL_HIGH
PUBLIC NUMERIC T,N
INPUT PROMPT "n乗根=":N
INPUT PROMPT "X=":T
LET XX=T
DO
LET X=XX
SELECT CASE N
CASE 2
LET XX=X-F(X)/DF(X,1)
CASE 3
LET XX=X-F(X)/(DF(X,1)-DF(X,2)/FACT(2)*(F(X)/DF(X,1)))
CASE 4
LET XX=X-F(X)/(DF(X,1)-DF(X,2)/FACT(2)*(F(X)/DF(X,1))-DF(X,3)/FACT(3)*(F(X)/DF(X,1))^2)
CASE 5
LET XX=X-F(X)/(DF(X,1)-DF(X,2)/FACT(2)*(F(X)/DF(X,1))-DF(X,3)/FACT(3)*(F(X)/DF(X,1))^2-DF(X,4)/FACT(4)*(F(X)/DF(X,1))^3)
CASE ELSE
LET S=0
FOR I=2 TO N-1
LET S=S+DF(X,I)/FACT(I)*(F(X)/DF(X,1))^(I-1)
NEXT I
LET XX=X-F(X)/(DF(X,1)-S)
END SELECT
PRINT XX
LOOP UNTIL X=XX
PRINT XX
END
EXTERNAL FUNCTION F(X)
OPTION ARITHMETIC DECIMAL_HIGH
LET F=X^N-T
END FUNCTION
EXTERNAL FUNCTION DF(X,NN)
OPTION ARITHMETIC DECIMAL_HIGH
LET S=N
FOR I=1 TO NN-1
LET S=S*(N-I)
NEXT I
LET DF=S*X^(N-NN)
END FUNCTION
|
|