テイラー展開 しばっち 2008/02/05 23:17:12 (修正1回)
テイラー展開 |
返事を書く ノートメニュー |
しばっち <dihjvcfsyu> 2008/02/05 23:17:12 ** この記事は1回修正されてます | |
PUBLIC NUMERIC H
LET H=1/128 LET X=0 LET N=5 PRINT DIFF(X,A) FOR A=1 TO N PRINT DIFF(X,A)/FAC(A);"* (X";SIGN$(X);") ^";A NEXT A END EXTERNAL FUNCTION F(X) LET F=1/(1+X) !'LET F=COS(X)^SIN(X) !'LET F=1/COS(X) !'LET F=TAN(X) !'LET F=EXP(SIN(X)) END FUNCTION EXTERNAL FUNCTION DIFF(X,M) IF M>0 THEN LET DIFF=(DIFF(X+H,M-1)-DIFF(X-H,M-1))/(2*H) EXIT FUNCTION END IF IF M=0 THEN LET DIFF=F(X) END FUNCTION EXTERNAL FUNCTION FAC(X) LET S=1 FOR I=2 TO X LET S=S*I NEXT I LET FAC=S END FUNCTION EXTERNAL FUNCTION SIGN$(X) IF X<0 THEN LET SIGN$=" + "& STR$(ABS(X)) ELSE LET SIGN$=" - "& STR$(ABS(X)) END FUNCTION 2変数版 PUBLIC NUMERIC H LET H=1/128 LET X=0 LET Y=0 LET M=5 PRINT F(X,Y) FOR N=1 TO M FOR B=0 TO N LET A=N-B PRINT DIFF(X,A,Y,B)/FAC(A)/FAC(B);"* (X";SIGN$(X);") ^";A;"* (Y";SIGN$(Y);") ^";B NEXT B NEXT N END EXTERNAL FUNCTION F(X,Y) LET F=EXP(X)*SIN(Y) END FUNCTION EXTERNAL FUNCTION DIFF(X,M,Y,N) IF M>0 THEN LET DIFF=(DIFF(X+H,M-1,Y,N)-DIFF(X-H,M-1,Y,N))/(2*H) EXIT FUNCTION END IF IF N>0 THEN LET DIFF=(DIFF(X,M,Y+H,N-1)-DIFF(X,M,Y-H,N-1))/(2*H) EXIT FUNCTION END IF IF M=0 OR N=0 THEN LET DIFF=F(X,Y) END FUNCTION EXTERNAL FUNCTION FAC(X) LET S=1 FOR I=2 TO X LET S=S*I NEXT I LET FAC=S END FUNCTION EXTERNAL FUNCTION SIGN$(X) IF X<0 THEN LET SIGN$=" + "& STR$(ABS(X)) ELSE LET SIGN$=" - "& STR$(ABS(X)) END FUNCTION |
└!数値微分の誤差と計算量-再帰呼び出しによ... 山中和義 2008/02/06 22:34:27 (修正1回)