|
再帰呼出しによる多重積分 シンプソン則
PUBLIC NUMERIC LEVEL
INPUT PROMPT "多重積分 LEVEL=":LEVEL
DIM A(LEVEL),B(LEVEL),N(LEVEL),AA(LEVEL)
FOR I=1 TO LEVEL
!'INPUT PROMPT "下限 =":A(I)
!'INPUT PROMPT "上限 =":B(I)
!'INPUT PROMPT "分割数=":N(I)
READ A(I),B(I),N(I)
NEXT I
DATA 0,1,10
DATA 0,1,10
DATA 0,1,10
DATA 0,1,10
PRINT SIMPSONRECURSIVE(LEVEL,AA,A,B,N)
END
EXTERNAL FUNCTION SIMPSONRECURSIVE(LEV,AA(),A(),B(),N())
IF LEV=0 THEN
LET SIMPSONRECURSIVE=FUNC(AA)
ELSE
LET H=(B(LEV)-A(LEV))/N(LEV)/2
FOR K=0 TO N(LEV)-1
LET AA(LEV)=A(LEV)+H*K*2
LET S=S+1/3*H*SIMPSONRECURSIVE(LEV-1,AA,A,B,N)
LET AA(LEV)=A(LEV)+H*(2*K+1)
LET S=S+4/3*H*SIMPSONRECURSIVE(LEV-1,AA,A,B,N)
LET AA(LEV)=A(LEV)+H*(2*K+2)
LET S=S+1/3*H*SIMPSONRECURSIVE(LEV-1,AA,A,B,N)
NEXT K
LET SIMPSONRECURSIVE=S
END IF
END FUNCTION
EXTERNAL FUNCTION FUNC(X())
LET S=1
FOR I=1 TO LEVEL
LET S=S-X(I)*X(I)
NEXT I
IF S > 0 THEN
LET FUNC=SQR(S)
ELSE
LET FUNC=0
END IF
END FUNCTION
--------------------------------------------------------------
再帰呼出しによる多重積分 ガウス・ルジャンドル則
PUBLIC NUMERIC W(10),X(10),LEVEL
INPUT PROMPT "多重積分 LEVEL=":LEVEL
DIM A(LEVEL),B(LEVEL),XX(LEVEL),WW(LEVEL)
FOR I=1 TO LEVEL
READ A(I),B(I)
NEXT I
DATA 0,1
DATA 0,1
DATA 0,1
DATA 0,1
RESTORE 10
FOR I=1 TO 10
READ X(I),W(I)
NEXT I
PRINT LEGENDRERECURSIVE(LEVEL,XX,WW,A,B,10)
10 DATA -.9739065285171717,6.6671344308688138E-02 !'10点 ルジャンドル則
DATA -.8650633666889845,1.4945134915058059E-01
DATA -.6794095682990244,2.1908636251598204E-01
DATA -.4333953941292472,2.6926671930999636E-01
DATA -.1488743389816312,2.9552422471475287E-01
DATA .1488743389816312,2.9552422471475287E-01
DATA .4333953941292472,2.6926671930999636E-01
DATA .6794095682990244,2.1908636251598204E-01
DATA .8650633666889845,1.4945134915058059E-01
DATA .9739065285171717,6.6671344308688138E-02
END
EXTERNAL FUNCTION LEGENDRERECURSIVE(LEV,XX(),WW(),A(),B(),N)
IF LEV=0 THEN
LET LEGENDRERECURSIVE=FUNC(XX)
ELSE
FOR I=1 TO N
LET XX(LEV)=X(I)*(B(LEV)-A(LEV))/2+(A(LEV)+B(LEV))/2
LET WW(LEV)=W(I)*(B(LEV)-A(LEV))/2
LET S=S+LEGENDRERECURSIVE(LEV-1,XX,WW,A,B,N)*WW(LEV)
NEXT I
LET LEGENDRERECURSIVE=S
END IF
END FUNCTION
EXTERNAL FUNCTION FUNC(X())
LET S=1
FOR I=1 TO LEVEL
LET S=S-X(I)*X(I)
NEXT I
IF S > 0 THEN
LET FUNC=SQR(S)
ELSE
LET FUNC=0
END IF
END FUNCTION
--------------------------------------------------------------
再帰呼出しによる多重積分 チェビシェフ則
PUBLIC NUMERIC LEVEL
INPUT PROMPT "多重積分 LEVEL=":LEVEL
DIM A(LEVEL),B(LEVEL),N(LEVEL),X(LEVEL),W(LEVEL)
FOR I=1 TO LEVEL
!'INPUT PROMPT "下限 =":A(I)
!'INPUT PROMPT "上限 =":B(I)
!'INPUT PROMPT "分割数=":N(I)
READ A(I),B(I),N(I)
NEXT I
DATA 0,1,10
DATA 0,1,10
DATA 0,1,10
DATA 0,1,10
PRINT TCHEBYCHEFFRECURSIVE(LEVEL,X,W,A,B,N)
END
EXTERNAL FUNCTION TCHEBYCHEFFRECURSIVE(LEV,XX(),WW(),A(),B(),N())
IF LEV=0 THEN
LET TCHEBYCHEFFRECURSIVE=FUNC(XX)
ELSE
FOR I=0 TO N(LEV)-1
LET XX(LEV)=COS((2*I+1)/2/N(LEV)*PI)*(B(LEV)-A(LEV))/2+(A(LEV)+B(LEV))/2
LET WW(LEV)=SQR((B(LEV)-XX(LEV))*(XX(LEV)-A(LEV)))
LET S=S+TCHEBYCHEFFRECURSIVE(LEV-1,XX,WW,A,B,N)*WW(LEV)
NEXT I
LET TCHEBYCHEFFRECURSIVE=S*PI/N(LEV)
END IF
END FUNCTION
EXTERNAL FUNCTION FUNC(X())
LET S=1
FOR I=1 TO LEVEL
LET S=S-X(I)*X(I)
NEXT I
IF S > 0 THEN
LET FUNC=SQR(S)
ELSE
LET FUNC=0
END IF
END FUNCTION
--------------------------------------------------------------
再帰呼出しによる多重積分 二重指数関数法(DE法)
[a,b] q(t)=(b-a)/2*TANH(π/2*SINH(t))+(a+b)/2 q'(t)=π/2*(B-A)/2*COSH(X)*SECH(π/2*SINH(X))^2
[0,∞] q(t)=EXP(π/2*SINH(t)) q'(t)=π/2*COSH(t)*EXP(π/2*SINH(t))
[-∞,∞] q(t)=SINH(π/2*SINH(t)) q'(t)=π/2*COSH(t)*COSH(π/2*SINH(t))
無限区間多重積分
PUBLIC NUMERIC LEVEL
INPUT PROMPT "多重積分 LEVEL=":LEVEL
DIM X(LEVEL)
PRINT DE(LEVEL,X,1/16);PI^(LEVEL/2)
END
EXTERNAL FUNCTION DE(LEV,X(),H)
IF LEV=0 THEN
LET DE=FUNC(X)
ELSE
FOR K=-4 TO 4 STEP H !'(要)調整 K=-6~6,H=1/1000 程度
LET X(LEV)=Q(K)
LET S=S+H*DE(LEV-1,X,H)*QQ(K)
NEXT K
LET DE=S
END IF
END FUNCTION
EXTERNAL FUNCTION Q(X)
LET Q=SINH(PI/2*SINH(X))
END FUNCTION
EXTERNAL FUNCTION QQ(X)
LET QQ=PI/2*COSH(X)*COSH(PI/2*SINH(X))
END FUNCTION
EXTERNAL FUNCTION FUNC(X())
LET S=0
FOR I=1 TO LEVEL
LET S=S-X(I)*X(I)
NEXT I
LET FUNC=EXP(S)
END FUNCTION
|
|