|
!' トラウブ法(TRAUB法)
PUBLIC NUMERIC T
INPUT PROMPT "X=": T
LET EPS=1E-8
LET X0=T
LET X2=1
LET X1=(X0+X2)/2
LET Y0=F(X0)
LET Y1=F(X1)
LET Y2=F(X2)
LET DX=(X0-X2)/2
LET D1=(Y0-Y1)/DX
DO
LET D2=D1
LET D1=(Y0-Y1)/DX
LET H=(D1-D2)/(X0-X2)
LET OME=D1+(X0-X1)*H
LET S=OME*OME-4*Y0*H
IF S>0 THEN
LET SQ=SQR(S)
IF OME<0 THEN LET SQ=-SQ
LET DX=-2*Y0/(OME+SQ)
ELSE
LET DX=-.5*OME/EPS
END IF
LET X=X0+DX
LET Y=F(X)
LET X2=X1
LET Y2=Y1
LET X1=X0
LET Y1=Y0
LET X0=X
LET Y0=Y
IF ABS(F(X))<EPS THEN EXIT DO
PRINT X
LOOP
PRINT X;X*X
END
EXTERNAL FUNCTION F(X)
LET F=X*X-T
END FUNCTION
|
|