|
> No.4423[元記事へ]
yoshipyutaさんへのお返事です。
> f(z)=z^3-1の流域表示(Newtonのフラクタル)は十進BASICのサンプルプログラムにありますが(Real partとimaginarupartに分けて計算)、option arithmetic commplexで一般の複素関数f(z)にも適用できるようにならないでしょうか。Algebraが嫌いなKidsでもz^4-1まではReとImに分けて研究できるのですが。本来は私がプログラムを作成して教えなければならないのですが、どうにも苦手です(国内外にNewton's Basinsの図は数多くありますが、表示ソフトがあまりありません)。f(z)のNewtonのフラクタル表示を是非、十進BASICで作成してください。
以下のようなプログラムでよろしいでしょうか?
OPTION ARITHMETIC COMPLEX
LET SIZE=800
CALL GINIT(SIZE,SIZE)
LET LEFT=-1.5
LET RIGHT=1.5
LET BOTTOM=1.5
LET TOP=-1.5
LET EPS=1E-5
LET KS=50
DO
CLEAR
SET WINDOW LEFT,RIGHT,BOTTOM,TOP
LET DX=(RIGHT-LEFT)/SIZE
LET DY=(TOP-BOTTOM)/SIZE
FOR ZR=LEFT TO RIGHT STEP DX
FOR ZI=BOTTOM TO TOP STEP DY
LET XX=COMPLEX(ZR,ZI)
FOR K=1 TO KS
LET X=XX
WHEN EXCEPTION IN
LET XX=X-FUNC(X)/DIFF7(X)
USE
EXIT FOR
END WHEN
IF ABS(X-XX)<EPS THEN
LET C=MOD(K,7)
CALL PSET(ZR,ZI,C+1)
EXIT FOR
END IF
NEXT K
NEXT ZI
NEXT ZR
PAUSE "拡大する範囲を指定してください"
CALL GETSQUARE(LEFT,TOP,RIGHT,BOTTOM)
IF LEFT=RIGHT THEN EXIT DO
LOOP
END
EXTERNAL FUNCTION FUNC(X)
OPTION ARITHMETIC COMPLEX
!'LET FUNC=X^3-1
LET FUNC=X^4-1
!'LET FUNC=COMPLEX(-1,1)*X^5+COMPLEX(1,-2)*X^4+COMPLEX(-3,1)*X^3+COMPLEX(0,-2)*X^2+COMPLEX(3,0)*X+COMPLEX(-5,3)
!'LET FUNC=CSIN(X)-.5
!'LET FUNC=CTAN(X)-1
!'LET FUNC=CCOSH(X)-2
!'LET FUNC=LOG(X)-.5
!'LET FUNC=EXP(X)-2
END FUNCTION
EXTERNAL SUB PSET(X,Y,C)
OPTION ARITHMETIC COMPLEX
SET POINT COLOR C
PLOT POINTS:X,Y
END SUB
EXTERNAL SUB GINIT(XSIZE,YSIZE)
OPTION ARITHMETIC COMPLEX
SET BITMAP SIZE XSIZE,YSIZE
!'SET WINDOW 0 , XSIZE-1 , YSIZE-1, 0
SET POINT STYLE 1
SET COLOR MIX(0) 0,0,0
SET COLOR MIX(1) 0,0,1
SET COLOR MIX(2) 1,0,0
SET COLOR MIX(3) 1,0,1
SET COLOR MIX(4) 0,1,0
SET COLOR MIX(5) 0,1,1
SET COLOR MIX(6) 1,1,0
SET COLOR MIX(7) 1,1,1
CLEAR
END SUB
EXTERNAL SUB GETSQUARE(L,T,R,B)
OPTION ARITHMETIC COMPLEX
ASK LINE STYLE LSTYLE
SET DRAW MODE NOTXOR
SET LINE STYLE 2
DO
MOUSE POLL L,T,I,J
LOOP WHILE I=0
LET L0=L
LET T0=T
LET R0=L0
LET B0=T0
PLOT LINES:L0,T0;L0,B0;R0,B0;R0,T0;L0,T0
DO WHILE I=1
MOUSE POLL R,B,I,J
LET W=R-L
LET H=T-B
IF ABS(H)<ABS(W) THEN
LET B=T-SGN(H)*ABS(W)
ELSE
LET R=L+SGN(W)*ABS(H)
END IF
IF L0<>L OR R0<>R OR B0<>B OR T0<>T THEN
PLOT LINES:L0,T0;L0,B0;R0,B0;R0,T0;L0,T0
PLOT LINES:L,T;L,B;R,B;R,T;L,T
LET L0=L
LET T0=T
LET R0=R
LET B0=B
END IF
LOOP
WAIT DELAY 1
PLOT LINES:L,T;L,B;R,B;R,T;L,T
SET DRAW MODE OVERWRITE
SET LINE STYLE LSTYLE
IF L>R THEN SWAP L,R
IF B>T THEN SWAP B,T
END SUB
EXTERNAL FUNCTION DIFF7(X)
OPTION ARITHMETIC COMPLEX
LET H=1/256
LET DIFF7=(-FUNC(X-3*H)+9*FUNC(X-2*H)-45*FUNC(X-H)+45*FUNC(X+H)-9*FUNC(X+2*H)+FUNC(X+3*H))/(60*H)
END FUNCTION
EXTERNAL FUNCTION CSIN(Z) !'sine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=SIN(X)*COSH(Y)
LET XI=COS(X)*SINH(Y)
LET CSIN=COMPLEX(XR,XI)
END FUNCTION
EXTERNAL FUNCTION CCOS(Z) !'cosine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=COS(X)*COSH(Y)
LET XI=-SIN(X)*SINH(Y)
LET CCOS=COMPLEX(XR,XI)
END FUNCTION
EXTERNAL FUNCTION CTAN(Z) !'tangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COS(2*X)+COSH(2*Y)
LET XR=SIN(2*X)/D
LET XI=SINH(2*Y)/D
LET CTAN=COMPLEX(XR,XI)
END FUNCTION
EXTERNAL FUNCTION CSINH(Z) !'hyperbolic sine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=SINH(X)*COS(Y)
LET XI=COSH(X)*SIN(Y)
LET CSINH=COMPLEX(XR,XI)
END FUNCTION
EXTERNAL FUNCTION CCOSH(Z) !'hyperbolic cosine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=COSH(X)*COS(Y)
LET XI=SINH(X)*SIN(Y)
LET CCOSH=COMPLEX(XR,XI)
END FUNCTION
EXTERNAL FUNCTION CTANH(Z) !'hyperbolic tangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COS(2*Y)+COSH(2*X)
LET XR=SINH(2*X)/D
LET XI=SIN(2*Y)/D
LET CTANH=COMPLEX(XR,XI)
END FUNCTION
|
|