複素数ライブラリー

 投稿者:しばっち  投稿日:2009年 9月27日(日)13時29分39秒
  複素数モードで使用できる関数をいくつか定義してみました。
なお、作成には「Maxima」を利用しました。 {ex.   realpart(cos(x+%i*y));  }
                                         {      imagpart(cos(x+%i*y));  }


OPTION ARITHMETIC COMPLEX
LET X=COMPLEX(1,-2)
LET N=5
DIM A(N)
PRINT "X=";X;"(";REAL(X);IMAG(X);")"
PRINT "SIN=";CSIN(X);CSIN2(X)
PRINT "COS=";CCOS(X);CCOS2(X)
PRINT "TAN=";CTAN(X);CTAN2(X)
PRINT "COSEC=";CCOSEC(X);CCOSEC2(X)
PRINT "SEC=";CSEC(X);CSEC2(X)
PRINT "COTAN=";CCOTAN(X);CCOTAN2(X)
PRINT "SINH=";CSINH(X);CSINH2(X)
PRINT "COSH=";CCOSH(X);CCOSH2(X)
PRINT "TANH=";CTANH(X);CTANH2(X)
PRINT "COSECH=";CCOSECH(X);CCOSECH2(X)
PRINT "SECH=";CSECH(X);CSECH2(X)
PRINT "COTANH=";CCOTANH(X);CCOTANH2(X)
PRINT "平方根=";CSQR(X);CEXP(CLOG(X)/2)
CALL CNPOW(X,N,A)
PRINT N;"乗根"
FOR I=1 TO N
   PRINT I;":";A(I);A(I)^N
NEXT I
LET Y=COMPLEX(1,2)
PRINT "X^Y=";CPOW(X,Y);CEXP(Y*CLOG(X))
END

! 三角関数

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 CSIN2(Z)
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET CSIN2=(CEXP(I*Z)-CEXP(-I*Z))/(2*I)
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 CCOS2(Z)
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET CCOS2=(CEXP(I*Z)+CEXP(-I*Z))/2
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 CTAN2(Z)
OPTION ARITHMETIC COMPLEX
LET CTAN2=CSIN(Z)/CCOS(Z)
END FUNCTION

EXTERNAL  FUNCTION CCOSEC(Z) !'cosecant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COS(X)^2*SINH(Y)^2+SIN(X)^2*COSH(Y)^2
LET XR=SIN(X)*COSH(Y)/D
LET XI=-COS(X)*SINH(Y)/D
LET CCOSEC=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CCOSEC2(Z)
OPTION ARITHMETIC COMPLEX
LET CCOSEC2=1/CSIN(Z)
END FUNCTION

EXTERNAL  FUNCTION CSEC(Z) !'secant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SIN(X)^2*SINH(Y)^2+COS(X)^2*COSH(Y)^2
LET XR=COS(X)*COSH(Y)/D
LET XI=SIN(X)*SINH(Y)/D
LET CSEC=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CSEC2(Z)
OPTION ARITHMETIC COMPLEX
LET CSEC2=1/CCOS(Z)
END FUNCTION

EXTERNAL  FUNCTION CCOTAN(Z) !'cotangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COSH(2*Y)+COS(2*X)
LET DD=SINH(2*Y)^2+SIN(2*X)^2
LET XR=SIN(2*X)*D/DD
LET XI=-SINH(2*Y)*D/DD
LET CCOTAN=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CCOTAN2(Z)
OPTION ARITHMETIC COMPLEX
LET CCOTAN2=1/CTAN(Z)
END FUNCTION

! 逆三角関数

EXTERNAL  FUNCTION CASIN(Z) !'arcsine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SQR((Y^2-X^2+1)^2+4*X^2*Y^2)
LET S=SQR(D-Y^2+X^2-1)/SQR(2)
LET SS=SQR(D+Y^2-X^2+1)/SQR(2)
IF X*Y>0 THEN
   LET XR=-ATAN2(S-X,SS-Y)
   LET XI=-LOG((SS-Y)^2+(X-S)^2)/2
ELSE
   LET XR=ATAN2(S+X,SS-Y)
   LET XI=-LOG((SS-Y)^2+(X+S)^2)/2
END IF
LET CASIN=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL FUNCTION CASIN2(Z)
OPTION ARITHMETIC COMPLEX
LET CASIN2=CATAN(Z/CSQR(1-Z*Z))
END FUNCTION

EXTERNAL  FUNCTION CASIN3(Z)
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET CASIN3=-I*CLOG(CSQR(1-Z*Z)+Z*I)
END FUNCTION

EXTERNAL  FUNCTION CACOS(Z) !'arccosine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SQR((Y^2-X^2+1)^2+4*X^2*Y^2)
LET S=SQR(D+Y^2-X^2+1)/SQR(2)
LET SS=SQR(D-Y^2+X^2-1)/SQR(2)
IF X*Y>0 THEN
   LET XR=ATAN2(S+Y,X+SS)
   LET XI=-LOG((S+Y)^2+(SS+X)^2)/2
ELSE
   LET XR=ATAN2(S+Y,X-SS)
   LET XI=-LOG((S+Y)^2+(X-SS)^2)/2
END IF
LET CACOS=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CACOS2(Z)
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET CACOS2=-I*CLOG(Z+I*CSQR(1-Z*Z))
END FUNCTION

EXTERNAL  FUNCTION CATAN(Z) !'arctangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=(ATAN2(X,Y+1)+ATAN2(X,1-Y))/2
LET XI=-LOG((1-Y)^2+X^2)/4+LOG((Y+1)^2+X^2)/4
LET CATAN=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CATAN2(Z)
OPTION ARITHMETIC COMPLEX
LET I=SQR(-1)
LET CATAN2=I/2*CLOG((I+Z)/(I-Z))
END FUNCTION

EXTERNAL  FUNCTION CACOSEC(Z) !'arccosecant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET S=X^2-Y^2
LET SS=4*X^2*Y^2
LET D=S^2+SS
LET E=S/D
LET DD=SS/D^2
LET EE=Y^2/D-X^2/D+1
IF X*Y>=0 THEN
   LET XR= ATAN2(SQR(SQR((1-E)^2+DD)+E-1)/SQR(2)+X/(X^2+Y^2),SQR(SQR((1-E)^2+DD)-E+1)/SQR(2)+Y/(X^2+Y^2))
   LET XI=-LOG((SQR(SQR(EE^2+DD)+EE)/SQR(2)+Y/(Y^2+X^2))^2+(X/(X^2+Y^2)+SQR(SQR(EE^2+DD)-EE)/SQR(2))^2)/2
ELSE
   LET XR=-ATAN2(SQR(SQR((1-E)^2+DD)+E-1)/SQR(2)-X/(X^2+Y^2),SQR(SQR((1-E)^2+DD)-E+1)/SQR(2)+Y/(X^2+Y^2))
   LET XI=-LOG((SQR(SQR(EE^2+DD)+EE)/SQR(2)+Y/(Y^2+X^2))^2+(X/(X^2+Y^2)-SQR(SQR(EE^2+DD)-EE)/SQR(2))^2)/2
END IF
LET CACOSEC=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CACOSEC2(Z)
OPTION ARITHMETIC COMPLEX
LET CACOSEC2=CASIN(1/Z)
END FUNCTION

EXTERNAL  FUNCTION CACOSEC3(Z)
OPTION ARITHMETIC COMPLEX
LET CACOSEC3=CATAN(1/CSQR(Z*Z-1))
END FUNCTION

EXTERNAL  FUNCTION CASEC(Z) !'arcsecant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET S=X^2-Y^2
LET SS=4*X^2*Y^2
LET D=S^2+SS
LET E=S/D
LET DD=SS/D^2
LET EE=Y^2/D-X^2/D+1
IF X*Y>=0 THEN
   LET XR=ATAN2(SQR(SQR((1-E)^2+DD)-E+1)/SQR(2)-Y/(X^2+Y^2),X/(X^2+Y^2)-SQR(SQR((1-E)^2+DD)+E-1)/SQR(2))
   LET XI=-LOG((SQR(SQR(EE^2+DD)+EE)/SQR(2)-Y/(Y^2+X^2))^2+(X/(X^2+Y^2)-SQR(SQR(EE^2+DD)-EE)/SQR(2))^2)/2
ELSE
   LET XR=ATAN2(SQR(SQR((1-E)^2+DD)-E+1)/SQR(2)-Y/(X^2+Y^2),X/(X^2+Y^2)+SQR(SQR((1-E)^2+DD)+E-1)/SQR(2))
   LET XI=-LOG((SQR(SQR(EE^2+DD)+EE)/SQR(2)-Y/(Y^2+X^2))^2+(X/(X^2+Y^2)+SQR(SQR(EE^2+DD)-EE)/SQR(2))^2)/2
END IF
LET CASEC=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL FUNCTION CASEC2(Z)
OPTION ARITHMETIC COMPLEX
LET CASEC2=CATAN(CSQR(Z*Z-1))
END FUNCTION
 

Re: 複素数ライブラリー

 投稿者:しばっち  投稿日:2009年 9月27日(日)13時30分40秒
  > No.574[元記事へ]

続き


EXTERNAL FUNCTION CASEC3(Z)
OPTION ARITHMETIC COMPLEX
LET CASEC3=CACOS(1/Z)
END FUNCTION

EXTERNAL  FUNCTION CACOTAN(Z) !'arccotangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=X^2+Y^2
LET XR=(ATAN2(X/D,Y/D+1)+ATAN2(X/D,1-Y/D))/2
LET XI=-LOG((Y/D+1)^2+X^2/D^2)/4+LOG((1-Y/D)^2+X^2/D^2)/4
LET CACOTAN=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CACOTAN2(Z)
OPTION ARITHMETIC COMPLEX
LET CACOTAN2=CATAN(1/Z)
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 CSINH2(Z)
OPTION ARITHMETIC COMPLEX
LET CSINH2=(CEXP(Z)-CEXP(-Z))/2
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 CCOSH2(Z)
OPTION ARITHMETIC COMPLEX
LET CCOSH2=(CEXP(Z)+CEXP(-Z))/2
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

EXTERNAL FUNCTION CTANH2(Z)
OPTION ARITHMETIC COMPLEX
LET CTANH2=CSINH(Z)/CCOSH(Z)
END FUNCTION

EXTERNAL  FUNCTION CTANH3(Z)
OPTION ARITHMETIC COMPLEX
LET CTANH3=-CEXP(-Z)/(CEXP(Z)+CEXP(-Z))*2+1
END FUNCTION

EXTERNAL  FUNCTION CCOSECH(Z) !'hyperbolic cosecant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COSH(X)^2*SIN(Y)^2+SINH(X)^2*COS(Y)^2
LET XR=SINH(X)*COS(Y)/D
LET XI=-COSH(X)*SIN(Y)/D
LET CCOSECH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CCOSECH2(Z)
OPTION ARITHMETIC COMPLEX
LET CCOSECH2=1/CSINH(Z)
END FUNCTION

EXTERNAL  FUNCTION CSECH(Z) !'hyperbolic secant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SINH(X)^2*SIN(Y)^2+COSH(X)^2*COS(Y)^2
LET XR=COSH(X)*COS(Y)/D
LET XI=-SINH(X)*SIN(Y)/D
LET CSECH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CSECH2(Z)
OPTION ARITHMETIC COMPLEX
LET CSECH2=1/CCOSH(Z)
END FUNCTION

EXTERNAL  FUNCTION CCOTANH(Z) !'hyperbolic cotangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=COS(2*Y)+COSH(2*X)
LET DD=SIN(2*Y)^2+SINH(2*X)^2
LET XR=SINH(2*X)*D/DD
LET XI=-SIN(2*Y)*D/DD
LET CCOTANH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CCOTANH2(Z)
OPTION ARITHMETIC COMPLEX
LET CCOTANH2=1/CTANH(Z)
END FUNCTION

EXTERNAL FUNCTION CCOTANH3(Z)
OPTION ARITHMETIC COMPLEX
LET CCOTANH3=CEXP(-Z)/(CEXP(Z)-CEXP(-Z))*2+1
END FUNCTION

! 逆双曲線関数

EXTERNAL  FUNCTION CASINH(Z) !'arc-hyperbolic sine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SQR((-Y^2+X^2+1)^2+4*X^2*Y^2)
IF X*Y>=0 THEN
   LET XR=LOG((SQR(D+Y^2-X^2-1)/SQR(2)+Y)^2+(SQR(D-Y^2+X^2+1)/SQR(2)+X)^2)/2
   LET XI=ATAN2(SQR(D+Y^2-X^2-1)/SQR(2)+Y,SQR(D-Y^2+X^2+1)/SQR(2)+X)
ELSE
   LET XR=LOG((Y-SQR(D+Y^2-X^2-1)/SQR(2))^2+(SQR(D-Y^2+X^2+1)/SQR(2)+X)^2)/2
   LET XI=-ATAN2(SQR(D+Y^2-X^2-1)/SQR(2)-Y,SQR(D-Y^2+X^2+1)/SQR(2)+X)
END IF
LET CASINH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL FUNCTION CASINH2(Z)
OPTION ARITHMETIC COMPLEX
LET CASINH2=CLOG(Z+CSQR(Z*Z+1))
END FUNCTION

EXTERNAL  FUNCTION CACOSH(Z) !'arc-hyperbolic cosine
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=SQR(Y^2+(X+1)^2)
LET DD=SQR(Y^2+(X-1)^2)
IF Y>=0 THEN
   LET XR=LOG((SQR(D+X+1)/2+SQR(DD+X-1)/2)^2+(SQR(D-X-1)/2+SQR(DD-X+1)/2)^2)
   LET XI=2*ATAN2(SQR(D-X-1)/2+SQR(DD-X+1)/2,SQR(D+X+1)/2+SQR(DD+X-1)/2)
ELSE
   LET XR=LOG((SQR(D+X+1)/2+SQR(DD+X-1)/2)^2+(-SQR(D-X-1)/2-SQR(DD-X+1)/2)^2)
   LET XI=-2*ATAN2(SQR(D-X-1)/2+SQR(DD-X+1)/2,SQR(D+X+1)/2+SQR(DD+X-1)/2)
END IF
LET CACOSH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL FUNCTION CACOSH2(Z)
OPTION ARITHMETIC COMPLEX
LET CACOSH2=CLOG(Z+CSQR(Z*Z-1))
END FUNCTION

EXTERNAL  FUNCTION CATANH(Z) !'arc-hyperbolic tangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR=LOG(Y^2+(X+1)^2)/4-LOG(Y^2+(1-X)^2)/4
LET XI=(ATAN2(Y,X+1)+ATAN2(Y,1-X))/2
LET CATANH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL FUNCTION CATANH2(Z)
OPTION ARITHMETIC COMPLEX
LET CATANH2=CLOG((1+Z)/(1-Z))/2
END FUNCTION

EXTERNAL  FUNCTION CACOSECH(Z) !'arc-hyperbolic cosecant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET S=(X^2-Y^2)^2+4*X^2*Y^2
LET D=Y^2/S
LET DD=X^2/S
LET SS=4*X^2*Y^2/S^2
LET E=(X^2-Y^2)/S
IF X*Y>0 THEN
   LET XR=LOG((-SQR(SQR((-D+DD+1)^2+SS)+D-DD-1)/SQR(2)-Y/(X^2+Y^2))^2+(SQR(SQR((-D+DD+1)^2+SS)-D+DD+1)/SQR(2)+X/(X^2+Y^2))^2)/2
   LET XI=-ATAN2(SQR(SQR((E+1)^2+SS)-E-1)/SQR(2)+Y/(X^2+Y^2),SQR(SQR((E+1)^2+SS)+E+1)/SQR(2)+X/(X^2+Y^2))
ELSE
   LET XR=LOG((SQR(SQR((-D+DD+1)^2+SS)+D-DD-1)/SQR(2)-Y/(X^2+Y^2))^2+(SQR(SQR((-D+DD+1)^2+SS)-D+DD+1)/SQR(2)+X/(X^2+Y^2))^2)/2
   LET XI=ATAN2(SQR(SQR((E+1)^2+SS)-E-1)/SQR(2)-Y/(X^2+Y^2),SQR(SQR((E+1)^2+SS)+E+1)/SQR(2)+X/(X^2+Y^2))
END IF
LET CACOSECH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CACOSECH2(Z)
OPTION ARITHMETIC COMPLEX
LET CACOSECH2=CASINH(1/Z)
END FUNCTION

EXTERNAL FUNCTION CACOSECH3(Z)
OPTION ARITHMETIC COMPLEX
LET CACOSECH3=CLOG((CSQR(Z*Z+1)+1)/Z)
END FUNCTION

EXTERNAL  FUNCTION CASECH(Z) !'arc-hyperbolic secant
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=X/(X^2+Y^2)
LET DD=Y^2/(X^2+Y^2)^2
IF Y>0 THEN
   LET XR=LOG((SQR(SQR((D+1)^2+DD)+D+1)/2+SQR(SQR((D-1)^2+DD)+D-1)/2)^2+(-SQR(SQR((D+1)^2+DD)-D-1)/2-SQR(SQR((D-1)^2+DD)-D+1)/2)^2)
   LET XI=-2*ATAN2(SQR(SQR((D+1)^2+DD)-D-1)/2+SQR(SQR((D-1)^2+DD)-D+1)/2,SQR(SQR((D+1)^2+DD)+D+1)/2+SQR(SQR((D-1)^2+DD)+D-1)/2)
ELSE
   LET XR=LOG((SQR(SQR((D+1)^2+DD)+D+1)/2+SQR(SQR((D-1)^2+DD)+D-1)/2)^2+(SQR(SQR((D+1)^2+DD)-D-1)/2+SQR(SQR((D-1)^2+DD)-D+1)/2)^2)
   LET XI=2*ATAN2(SQR(SQR((D+1)^2+DD)-D-1)/2+SQR(SQR((D-1)^2+DD)-D+1)/2,SQR(SQR((D+1)^2+DD)+D+1)/2+SQR(SQR((D-1)^2+DD)+D-1)/2)
END IF
LET CASECH=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CASECH2(Z)
OPTION ARITHMETIC COMPLEX
LET CASECH2=CACOSH(1/Z)
END FUNCTION

EXTERNAL FUNCTION CASECH3(Z)
OPTION ARITHMETIC COMPLEX
LET CASECH3=CLOG((CSQR(1-Z*Z)+1)/Z)
END FUNCTION

EXTERNAL  FUNCTION CACOTANH(Z) !'arc-hyperbolic cotangent
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET D=X/(X^2+Y^2)
LET S=Y/(X^2+Y^2)
LET DD=S^2
LET XR=LOG((D+1)^2+DD)/4-LOG((1-D)^2+DD)/4
LET XI=(-ATAN2(S,D+1)-ATAN2(S,1-D))/2
LET CACOTANH=COMPLEX(XR,XI)
END FUNCTION
 

Re: 複素数ライブラリー

 投稿者:しばっち  投稿日:2009年 9月27日(日)13時32分37秒
  > No.575[元記事へ]

続き



EXTERNAL  FUNCTION CACOTANH2(Z)
OPTION ARITHMETIC COMPLEX
LET CACOTANH2=CATANH(1/Z)
END FUNCTION

EXTERNAL FUNCTION CACOTANH3(Z)
OPTION ARITHMETIC COMPLEX
LET CACOTANH3=CLOG((Z+1)/(Z-1))/2
END FUNCTION

! その他

EXTERNAL  FUNCTION CABS(Z) !'絶対値
OPTION ARITHMETIC COMPLEX
LET CABS=SQR(RE(Z)^2+IM(Z)^2)
END FUNCTION

EXTERNAL  FUNCTION CSQR(Z) !'平方根
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET R=SQR(X*X+Y*Y)
LET XR=SQR(R+X)/SQR(2)
IF Y>=0 THEN
   LET  XI=SQR(R-X)/SQR(2)
ELSE
   LET  XI=-SQR(R-X)/SQR(2)
END IF
LET CSQR=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CLOG(Z) !'対数
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR = LOG(X * X + Y * Y) / 2
LET XI = ATAN2(Y, X)
LET CLOG=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CEXP(Z) !'指数
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET XR = EXP(X) * COS(Y)
LET XI = EXP(X) * SIN(Y)
LET CEXP=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CARG(Z) !'偏角
OPTION ARITHMETIC COMPLEX
LET  CARG = ATAN2(IM(Z), RE(Z))
END FUNCTION

EXTERNAL  FUNCTION CPOW(X,Y) !'(A+Bi)^(C+Di)
OPTION ARITHMETIC COMPLEX
LET A=RE(X)
LET B=IM(X)
LET C=RE(Y)
LET D=IM(Y)
LET XR=(B^2+A^2)^(C/2)*EXP(-ATAN2(B,A)*D)*COS(LOG(B^2+A^2)*D/2+ATAN2(B,A)*C)
LET XI=(B^2+A^2)^(C/2)*EXP(-ATAN2(B,A)*D)*SIN(LOG(B^2+A^2)*D/2+ATAN2(B,A)*C)
LET CPOW=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  SUB CNPOW(Z, N, V()) !'(A+Bi)^(1/N)
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET  R = (X * X + Y * Y)^(1 / (2 * N))
LET TH = ATAN2(Y,X)
LET  A = R * COS(TH / N)
LET  B = R * SIN(TH / N)
FOR I = 1 TO N
   LET  C = COS(2 * PI / N * I)
   LET  S = SIN(2 * PI / N * I)
   LET  AA = A * C - B * S
   LET  BB = B * C + A * S
   LET  V(I) = COMPLEX(AA,BB)
NEXT I
END SUB

EXTERNAL  FUNCTION CRUIJYO(Z, N) !'(A+Bi)^N
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
LET  N = INT(N)
LET  R = (X * X + Y * Y)^(N / 2)
LET TH=ATAN2(Y,X)
LET  XR = R * COS(TH * N)
LET  XI = R * SIN(TH * N)
LET CRUIJYO=COMPLEX(XR,XI)
END FUNCTION

EXTERNAL  FUNCTION CCONJ(Z) !'共役数
OPTION ARITHMETIC COMPLEX
LET CCONJ=COMPLEX(RE(Z),-IM(Z))
END FUNCTION

EXTERNAL  FUNCTION REAL(Z) !'実部
OPTION ARITHMETIC COMPLEX
LET REAL=CABS(Z)*COS(CARG(Z))
END FUNCTION

EXTERNAL  FUNCTION IMAG(Z) !'虚部
OPTION ARITHMETIC COMPLEX
LET IMAG=CABS(Z)*SIN(CARG(Z))
END FUNCTION

EXTERNAL  SUB CPRINT(Z)
OPTION ARITHMETIC COMPLEX
LET X=RE(Z)
LET Y=IM(Z)
IF X=0 AND Y=0 THEN
   PRINT "0"
   EXIT SUB
END IF
IF Y=0 THEN
   IF X < 0 THEN PRINT "- ";
   PRINT STR$(ABS(X))
   EXIT SUB
END IF
IF X=0 THEN
   IF Y < 0 THEN PRINT "- ";
   IF ABS(Y)= 1 THEN
      PRINT "i"
      EXIT SUB
   END IF
   PRINT STR$(ABS(Y)); " i"
   EXIT SUB
END IF
IF X < 0 THEN PRINT "- ";
PRINT STR$(ABS(X)); " ";
IF Y < 0 THEN PRINT "- ";  ELSE PRINT "+ ";
IF ABS(Y)= 1 THEN
   PRINT "i"
   EXIT SUB
END IF
PRINT STR$(ABS(Y)); " i"
END SUB

EXTERNAL  FUNCTION ATAN2(Y,X) !'-π~π
OPTION ARITHMETIC COMPLEX
IF ABS(IM(X))<1E-4 AND ABS(IM(Y))<1E-4 THEN
   LET X=RE(X)
   LET Y=RE(Y)
ELSE
   PRINT "ERROR!!"
   STOP
END IF
LET ATAN2=ANGLE(X,Y)
!' LET L=ACOS(X/SQR(X*X+Y*Y))
!' IF Y<0 THEN LET ATAN2=-L ELSE LET ATAN2=L
END FUNCTION

!EXTERNAL  FUNCTION ATAN2(Y,X) '0~2π
!OPTION ARITHMETIC COMPLEX
!IF ABS(IM(X))<1E-4 AND ABS(IM(Y))<1E-4 THEN
!   LET X=RE(X)
!   LET Y=RE(Y)
!ELSE
!   PRINT "ERROR!!"
!   STOP
!END IF
!IF X<>0 THEN
!   LET TH=ATN(Y/X)
!   IF Y<>0 THEN
!      IF X>0 AND Y<0 THEN LET TH=TH+PI*2
!      IF X<0 THEN LET TH=TH+PI
!   ELSE
!      IF X<0 THEN LET TH=PI ELSE LET TH=0
!   END IF
!ELSE
!   LET TH=PI/2
!   IF Y<0 THEN LET TH=TH+PI
!END IF
!LET ATAN2=TH
!END FUNCTION
 

戻る