|
最小値を求める
PUBLIC NUMERIC H
LET H=1/256
LET HIGH=10
LET LOW=1
LET EPS=1E-8
DO
LET M=(HIGH+LOW)/2 !'二分法
IF DIFF(M,1)*DIFF(HIGH,1)>0 THEN LET HIGH=M ELSE LET LOW=M
LOOP UNTIL ABS(HIGH-LOW)<EPS
PRINT "MIN-X=";M
PRINT "最小値=";FUNC(M)
LET XX=10 !'初期値
DO
LET X=XX
LET XX=X-DIFF(X,1)/DIFF(X,2) !'ニュートン法 X=X-f'(X)/f''(X)
LOOP UNTIL ABS(X-XX)<EPS
PRINT "MIN-X=";XX
PRINT "最小値=";FUNC(XX)
END
EXTERNAL FUNCTION FUNC(X)
LET FUNC=(X^2-3)^2+3 !' X=SQR(3)の時、最小値 3
!'LET FUNC=X^3/3-2*X^2+3*X+2 !' X=3の時、極小値 2 f'(X)=(X-1)*(X-3)
END FUNCTION
EXTERNAL FUNCTION DIFF(X,N) !'n階微分
IF N=0 THEN
LET DIFF=FUNC(X)
ELSE
LET DIFF=(-DIFF(X+2*H,N-1)+8*DIFF(X+H,N-1)-8*DIFF(X-H,N-1)+DIFF(X-2*H,N-1))/(12*H)
END IF
END FUNCTION
! EXTERNAL FUNCTION DIFF(X,N)
! FOR J=0 TO N
! LET S=S+(-1)^J*COMB(N,J)*FUNC(X+(N/2-J)*H)
! NEXT J
! LET DIFF=S/(H^N)
! END FUNCTION
|
|