|
!' 高次収束式
OPTION ARITHMETIC DECIMAL_HIGH
OPTION BASE 0
PUBLIC NUMERIC N
INPUT PROMPT "n乗根=":N
INPUT PROMPT "X=":T
LET MODE=3
DIM A(N)
LET A(N)=1 !' A(N)*X^N+A(N-1)*X^(N-1)+...A(1)*X+A(0)=0
LET A(0)=-T
LET XX=T
DO
LET X=XX
CALL HORNER(A,X,Y,DY,DY2,DY3,DY4,DY5)
SELECT CASE MODE
CASE 2
LET XX=X-Y/DY !'NEWTON法
CASE 3
LET XX=X-Y/(DY-Y*DY2/(2*DY)) !'BAILEY法
CASE 4
LET XX=X-Y*(DY^2-DY2*Y/2)/(DY^3-Y*DY*DY2+DY3*Y^2/6) !'KISS法
CASE 5
LET XX=X+(4*Y^3*DY3-24*Y^2*DY*DY2+24*Y*DY^3)/(Y^3*DY4-8*Y^2*DY*DY3-6*Y^2*DY2^2+36*Y*DY^2*DY2-24*DY^4)
CASE 6
LET XX=X+(5*Y^4*DY4-40*Y^3*DY*DY3-30*Y^3*DY2^2+180*Y^2*DY^2*DY2-120*Y*DY^4)/(Y^4*DY5-10*Y^3*DY*DY4+(60*Y^2*DY^2-20*Y^3*DY2)*DY3+90*Y^2*DY*DY2^2-240*Y*DY^3*DY2+120*DY^5)
END SELECT
PRINT XX
LOOP UNTIL X=XX
PRINT X
END
EXTERNAL SUB HORNER(A(),X,Y,DY,DY2,DY3,DY4,DY5)
OPTION ARITHMETIC DECIMAL_HIGH
LET Y=A(N)
LET DY=Y
LET DY2=Y
LET DY3=Y
LET DY4=Y
LET DY5=Y
FOR I=N-1 TO 0 STEP -1
LET Y=Y*X+A(I)
IF I>0 THEN LET DY=DY*X+Y
IF I>1 THEN LET DY2=DY2*X+DY
IF I>2 THEN LET DY3=DY3*X+DY2
IF I>3 THEN LET DY4=DY4*X+DY3
IF I>4 THEN LET DY5=DY5*X+DY4
NEXT I
LET DY2=DY2*FACT(2)
LET DY3=DY3*FACT(3)
LET DY4=DY4*FACT(4)
LET DY5=DY5*FACT(5)
END SUB
|
|