|
!' 逆2次関数法
PUBLIC NUMERIC T
INPUT PROMPT "X=":T
LET EPS=1E-8
LET XMIN=1
LET XMAX=T
DO
LET XMID=(XMIN+XMAX)/2
LET YMIN=F(XMIN)
LET YMAX=F(XMAX)
LET YMID=F(XMID)
LET XNEW=XMIN*YMID*YMAX/(YMIN-YMID)/(YMIN-YMAX)+XMID*YMAX*YMIN/(YMID-YMAX)/(YMID-YMIN)+XMAX*YMIN*YMID/(YMAX-YMIN)/(YMAX-YMID)
IF XNEW>XMID THEN
LET XMIN=XMID
LET YMIN=YMID
ELSE
LET XMAX=XMID
LET YMAX=YMID
END IF
LET XMID=XNEW
LET YMID=F(XNEW)
PRINT XMID
LOOP UNTIL ABS(YMID)<EPS
PRINT XMID;XMID^3
END
EXTERNAL FUNCTION F(X)
LET F=X*X*X-T
END FUNCTION
|
|