#cs #INDEX# ==## Complex.au3 ##======================================================================================= Title .........: complex number calculations AutoIt Version : 3.2 Language ......: English Description ...: Special Functions for complex number calculations. Author(s) .....: Strahleman Date ..........: 2013-12-11 ================================================================================================================ #ce Global Const $pi = 3.141592653589793238462643383279 ; pi / Kreiszahl Global Const $e = 2.718281828459045235360287471352 ; Euler's number / Eulersche Zahl Global Const $em = 0.577215664901532860606512090082 ; Euler-Mascheroni constant / Euler-Mascheroni Konstante Global Const $ratio = 1.618033988749894848204586834365 ; golden mean / Goldener Schnitt Global Const $sq2pi = 2.5066282746310005024157652848110 ; Sqrt(2pi) Global Const $Reps = __Reps() ; Number of digits of computer precision / Anzahl Stellen Rechnergenauigkeit Global Const $meps = __Machine_Epsilon() ; computer precision / Rechnergenauigkeit Func __Reps() Return Round(Abs(Log(__Machine_Epsilon())/log(10)),0) EndFunc func __Machine_Epsilon() Local $eps, $Res = 1.0 Do $Res = 0.5 * $Res $eps = 1.0 + 0.5 * $Res Until $eps <= 1.0 Return $Res EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CmplxCheck() ; Description ...: Check of a complex number type. ; Syntax ........: _CmplxCheck($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns TRUE if $cmp is a complex number, else FALSE ; On Failure: = Sets @Error and returns FALSE. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Complex Number Check", "_CmplxCheck(_Cmplx( 3, 4 )) = " & _CmplxCheck(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _CmplxCheck($cmp) Local $cmpSize = DllStructGetSize($cmp) If @error Then Return SetError(1,0,False) Local $cmpReal = DllStructGetData($cmp, "Real") If @error Then Return SetError(1,0,False) Local $cmpImag = DllStructGetData($cmp, "Imag") If @error Then Return SetError(1,0,False) If Not( $cmpSize = 16 And IsNumber($cmpReal) And IsNumber($cmpImag) ) Then Return SetError(1,0,False) Return True EndFunc Func __Check(ByRef $_cmp) If Not _CmplxCheck($_cmp) Then If Not IsNumber($_cmp) Then Return False $_cmp = _Cmplx($_cmp, 0) EndIf Return True EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CmplxToStr() ; Description ...: Returns the difference of two complex numbers. ; Syntax ........: _CmplxToStr($cmp [, $imagUnit]) ; Parameters ....: $cmp = complex number. ; Return values .: On Success: = Returns a string of the complex number. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the imaginary part of a Complex Number", "_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )) = " & _CReal(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 ))) & "+" & _CImag(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )))) ; =============================================================================================================================== Func _CmplxToStr($cmp, $imagUnit="i") If Not __Check($cmp) Then Return SetError(1,0,0) Local $strC = "" Select Case DllStructGetData($cmp,"Imag") < 0 If DllStructGetData($cmp,"Imag") = -1 Then $strC = "-" & $imagUnit Else $strC = "-" & String(Abs(DllStructGetData($cmp,"Imag"))) & $imagUnit EndIf Case DllStructGetData($cmp,"Imag") = 0 $strC = "" Case DllStructGetData($cmp,"Imag") > 0 If DllStructGetData($cmp,"Imag") = 1 Then $strC = "+" & $imagUnit Else $strC = "+" & String(Abs(DllStructGetData($cmp,"Imag"))) & $imagUnit EndIf EndSelect Select Case DllStructGetData($cmp,"Real") < 0 $strC = "-" & String(Abs(DllStructGetData($cmp,"Real"))) & $strC Case DllStructGetData($cmp,"Real") = 0 If DllStructGetData($cmp,"Imag") = 1 Then $strC = $imagUnit ElseIf DllStructGetData($cmp,"Imag") = -1 Then $strC = "-" & $imagUnit elseif DllStructGetData($cmp,"Imag") = 0 Then $strC = 0 Else $strC = String(DllStructGetData($cmp,"Imag")) & $imagUnit EndIf Case DllStructGetData($cmp,"Real") > 0 $strC = String(Abs(DllStructGetData($cmp,"Real"))) & $strC EndSelect Return $strC EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Cmplx() ; Description ...: Returns a complex number. ; Syntax ........: _Cmplx(Const $real, Const $imag ) ; Parameters ....: $real = the real part of a complex number. ; $imag = the imaginary part of a complex number. ; Return values .: On Success: = Returns the complex number as a complex number type. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $real or $imag is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Create a Complex Number", "_Cmplx( 3, 4 ) = " & DllStructGetPtr(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _Cmplx($real=0, $imag=0) If Not IsNumber($real) or Not IsNumber($imag) Then Return SetError(1,0,0) Local $cmp = DllStructCreate("double Real;double Imag") DllStructSetData($cmp, "Real", $real) DllStructSetData($cmp, "Imag", $imag) Return $cmp EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CAbs() ; Description ...: Returns the absolute value of a complex number. ; Syntax ........: _CAbs($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns the absolute value of the complex number. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the absolute value of a Complex Number", "_CAbs(_Cmplx( 3, 4 )) = " & _CAbs(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _CAbs($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return Sqrt(DllStructGetData($cmp, "Real")^2 + DllStructGetData($cmp, "Imag")^2) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CArg() ; Description ...: Returns the argument of a complex number. ; Syntax ........: _CArg($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns the argument of the complex number in the Intervall of I = (-PI and PI]. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; 2 = the argument is indeterminate because the real and imaginary values are 0. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the argument of a Complex Number", "_CArg(_Cmplx( 3, 4 )) = " & _CArg(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _CArg($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $A[2] = [DllStructGetData($cmp, "Real"), DllStructGetData($cmp, "Imag")] Select Case $A[0] > 0 Return ATan($A[1]/$A[0]) Case $A[0] < 0 If $A[1] >= 0 Then Return ATan($A[1]/$A[0]) + $pi Else Return ATan($A[1]/$A[0]) - $pi EndIf Case $A[0] = 0 If $A[1] > 0 Then Return $pi/2 ElseIf $A[1] < 0 Then Return $pi/-2 ElseIf $A[1] = 0 Then Return SetError(2,0,0) EndIf EndSelect Return SetError(1,0,0) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CReal() ; Description ...: Returns the real part of a complex number. ; Syntax ........: _CReal($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns the real part of the complex. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the real part of a Complex Number", "_CReal(_Cmplx( 3, 4 )) = " & _CReal(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _CReal($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return DllStructGetData($cmp, "Real") EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CImag() ; Description ...: Returns the imaginary part of a complex number. ; Syntax ........: _CImag($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns the imaginary part of the complex. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the imaginary part of a Complex Number", "_CImag(_Cmplx( 3, 4 )) = " & _CImag(_Cmplx( 3, 4 ))) ; =============================================================================================================================== Func _CImag($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return DllStructGetData($cmp, "Imag") EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCon() ; Description ...: Returns the complex conjugate of a complex number. ; Syntax ........: _CCon($cmp) ; Parameters ....: $cmp = a complex number. ; Return values .: On Success: = Returns the complex conjugate. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a complex number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the imaginary part of a Complex Number", "_CCon(_Cmplx( 3, 4 )) = " & _CmplxToStr(_CCon(_Cmplx( 3, 4 )))) ; =============================================================================================================================== Func _CCon($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return _Cmplx(DllStructGetData($cmp, "Real"), -1 * DllStructGetData($cmp, "Imag")) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CAdd() ; Description ...: Returns the sum of two complex numbers. ; Syntax ........: _CAdd($cmp1, $cmp2) ; Parameters ....: $cmp1, $cmp2 = complex numbers. ; Return values .: On Success: = Returns the complex number of the addition. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp1 or $cmp2 is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the imaginary part of a Complex Number", "_CAdd(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )) = " & _CAdd(_Cmplx( 0, 1 ),_Cmplx( 1, 0 ))) ; =============================================================================================================================== Func _CAdd($cmp1, $cmp2) If Not __Check($cmp1) Or Not __Check($cmp2) Then Return SetError(1,0,0) Local $real = Round(DllStructGetData($cmp1,"Real") + DllStructGetData($cmp2,"Real") , $Reps - 1 ) Local $imag = Round(DllStructGetData($cmp1,"Imag") + DllStructGetData($cmp2,"Imag") , $Reps - 1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CSub() ; Description ...: Returns the difference of two complex numbers. ; Syntax ........: _CSub($cmp1, $cmp2) ; Parameters ....: $cmp1, $cmp2 = complex numbers. ; Return values .: On Success: = Returns the complex number of the subtraction ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp1 or $cmp2 is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the imaginary part of a Complex Number", "_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )) = " & _CReal(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 ))) & "+" & _CImag(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )))) ; =============================================================================================================================== Func _CSub($cmp1, $cmp2) If Not __Check($cmp1) Or Not __Check($cmp2) Then Return SetError(1,0,0) Local $real = Round(DllStructGetData($cmp1,"Real") - DllStructGetData($cmp2,"Real") , $Reps - 1 ) Local $imag = Round(DllStructGetData($cmp1,"Imag") - DllStructGetData($cmp2,"Imag") , $Reps - 1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CMul() ; Description ...: Returns the product of two complex numbers. ; Syntax ........: _CMul($cmp1, $cmp2) ; Parameters ....: $cmp = complex number. ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the product of two Complex Numbers", "_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )) = " & _CReal(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 ))) & "+" & _CImag(_CSub(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )))) ; =============================================================================================================================== Func _CMul($cmp1, $cmp2) If Not __Check($cmp1) Or Not __Check($cmp2) Then Return SetError(1,0,0) Local $real = Round((DllStructGetData($cmp1,"Real")*DllStructGetData($cmp2,"Real"))-(DllStructGetData($cmp1,"Imag")*DllStructGetData($cmp2, "Imag")),$Reps-1) Local $imag = Round((DllStructGetData($cmp1,"Real")*DllStructGetData($cmp2,"Imag"))+(DllStructGetData($cmp1,"Imag")*DllStructGetData($cmp2, "Real")),$Reps-1) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CDiv() ; Description ...: Returns the product of two complex numbers. ; Syntax ........: _CDiv($cmp1, $cmp2) ; Parameters ....: $cmp = complex number. ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; 2 = Division by zero ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: MsgBox(0x42040, "Get the product of two Complex Numbers", "_CDiv(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )) = " & _CReal(_CDiv(_Cmplx( 0, 1 ),_Cmplx( 1, 0 ))) & "+" & _CImag(_CDiv(_Cmplx( 0, 1 ),_Cmplx( 1, 0 )))) ; =============================================================================================================================== Func _CDiv($cmp1, $cmp2) If Not __Check($cmp1) Or Not __Check($cmp2) Then Return SetError(1,0,0) If DllStructGetData($cmp2, "Real") = 0 and DllStructGetData($cmp2, "Imag") = 0 Then Return SetError(2,0,0) Local $real = Round(1/(DllStructGetData($cmp2,"Real")^2 + DllStructGetData($cmp2,"Imag")^2) * ((DllStructGetData($cmp1,"Real")*DllStructGetData($cmp2, "Real"))+(DllStructGetData($cmp1,"Imag")*DllStructGetData($cmp2, "Imag"))),$Reps-1) Local $imag = Round(1/(DllStructGetData($cmp2,"Real")^2 + DllStructGetData($cmp2,"Imag")^2) * ((DllStructGetData($cmp2,"Real")*DllStructGetData($cmp1, "Imag"))-(DllStructGetData($cmp1,"Real")*DllStructGetData($cmp2, "Imag"))),$Reps-1) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CPow() ; Description ...: Returns the power of a complex number to an integer exponent. ; Syntax ........: _CPow($cmp1, $n) ; Parameters ....: $cmp = complex number ; $n = integer number ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CPow($cmp, $n) If Not __Check($cmp) Or Not IsNumber($n) Then Return SetError(1,0,0) Local $real = Round(_CAbs($cmp)^$n * Cos(_CArg($cmp) * $n),$Reps-1) Local $imag = Round(_CAbs($cmp)^$n * Sin(_CArg($cmp) * $n),$Reps-1) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CRoot() ; Description ...: Returns the root of a complex number to an real exponent. ; Syntax ........: _CRoot($cmp, $n) ; Parameters ....: $cmp = complex number ; $n = float number, degree of complex root ; $m = float number, count value of the complex root ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; 2 = the count value is greater than the root number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CRoot($cmp, $n, $m=0) If Not __Check($cmp) Or Not IsNumber($n) Or Not IsNumber($m) Then Return SetError(1,0,0) Local $R = _Rat($n) If $m >= $R[0] Then Return SetError(2,0,0) Local $real = Round(_CAbs($cmp)^(1/$n) * Cos((_CArg($cmp)+(2*$m*$pi))/$n),$Reps-1) Local $imag = Round(_CAbs($cmp)^(1/$n) * Sin((_CArg($cmp)+(2*$m*$pi))/$n),$Reps-1) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CLn() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CLn($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CLn($cmp, $m=0) If Not __Check($cmp) Or Not IsNumber($m) Then Return SetError(1,0,0) Local $real = Round(Log(_CAbs($cmp)),$Reps-1) Local $imag = Round(_CArg($cmp)+(2*$m*$pi),$Reps-1) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CSin() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CSin($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CSin($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round(Sin($x) * _Cosh($y) , $Reps-1 ) Local $imag = Round(Cos($x) * _Sinh($y) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCos() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCos($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCos($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round(Cos($x) * _Cosh($y) , $Reps-1 ) Local $imag = Round(Sin($x) * _Sinh($y) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CTan() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CTan($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CTan($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( Sin(2 * $x) / ( Cos(2 * $x) + _Cosh(2 * $y) ) , $Reps-1 ) Local $imag = Round( _Sinh(2 * $y) / ( Cos(2 * $x) + _Cosh(2 * $y) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CSec() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CSec($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CSec($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( (2 * Cos($x) * _Cosh($y) ) / ( Cos( 2 * $x ) + _Cosh( 2 * $y ) ) , $Reps-1 ) Local $imag = Round( (2 * Sin($x) * _Sinh($y) ) / ( Cos( 2 * $x ) + _Cosh( 2 * $y ) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCsc() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCsc($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCsc($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") If $y = 0 And $x = 0 Then Return SetError(2,0,0) Local $real = Round( (-2 * Sin($x) * _Cosh($y) ) / ( Cos( 2 * $x ) - _Cosh( 2 * $y ) ) , $Reps-1 ) Local $imag = Round( (2 * Cos($x) * _Sinh($y) ) / ( Cos( 2 * $x ) - _Cosh( 2 * $y ) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCot() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCot($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCot($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") If $y = 0 And $x = 0 Then Return SetError(2,0,0) Local $real = Round( -Sin(2 * $x) / ( Cos(2 * $x) - _Cosh(2 * $y) ) , $Reps-1 ) Local $imag = Round( _Sinh(2 * $y) / ( Cos(2 * $x) - _Cosh(2 * $y) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CASin() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CASin($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CASin($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round((_Sgn($x)/2) * ACos( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) - ($x^2 + $y^2) ) , $Reps-1 ) Local $imag = Round((_Sgn($y)/2) * _ACosh( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) + ($x^2 + $y^2) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACos() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACos($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACos($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( $pi/2 - ( (_Sgn($x)/2) * ACos( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) - ($x^2 + $y^2) ) ) , $Reps-1 ) Local $imag = Round((_Sgn($y)/2) * _ACosh( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) + ($x^2 + $y^2) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CATan() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CATan($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CATan($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = 0 If $x = 0 Then If Abs($y) <= 1 Then $real = 0 Else $real = $pi/2 * _Sgn($y) EndIf Else $real = 0.5 * ( ATan( ($x^2 + $y^2 - 1)/(2 * $x) ) + ($pi/2 * _Sgn($x)) ) EndIf $real = Round( $real, $Reps-1 ) Local $imag = Round( 0.5 * _ATanh( (2 * $y)/($x^2 + $y^2 + 1) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CASec() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CASec($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CASec($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) $cmp = _CDiv(1, $cmp) if @error Then Return SetError(2,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( $pi/2 - ( (_Sgn($x)/2) * ACos( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) - ($x^2 + $y^2) ) ) , $Reps-1 ) Local $imag = Round((_Sgn($y)/2) * _ACosh( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) + ($x^2 + $y^2) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACsc() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACsc($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACsc($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) $cmp = _CDiv(1, $cmp) if @error Then Return SetError(2,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round((_Sgn($x)/2) * ACos( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) - ($x^2 + $y^2) ) , $Reps-1 ) Local $imag = Round((_Sgn($y)/2) * _ACosh( Sqrt( ($x^2 + $y^2 - 1)^2 + (2 * $y)^2 ) + ($x^2 + $y^2) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACot() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACot($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACot($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = 0 If $x = 0 Then If Abs($y) <= 1 Then $real = $pi / 2 Else $real = $pi/2 * (1 - _Sgn($y)) EndIf Else $real = 0.5 * ($pi - ( ATan( ($x^2 + $y^2 - 1)/(2 * $x) ) + ($pi/2 * _Sgn($x)) ) ) EndIf $real = Round( $real, $Reps-1 ) Local $imag = Round( 0.5 * _ATanh( (2 * $y)/($x^2 + $y^2 + 1) ) , $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CSinh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CSinh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CSinh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( Cos($y) * _Sinh($x), $Reps-1 ) Local $imag = Round( Sin($y) * _Cosh($x), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCosh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCosh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCosh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( Cos($y) * _Cosh($x), $Reps-1 ) Local $imag = Round( Sin($y) * _Sinh($x), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CTanh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CTanh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CTanh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( (_Sinh(2 * $x)) / (_Cosh(2 * $x) + Cos(2 * $y)), $Reps-1 ) Local $imag = Round( (Sin(2 * $y)) / (_Cosh(2 * $x) + Cos(2 * $y)), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CSech() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CSech($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CSech($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") Local $real = Round( (2 * _Cosh($x) * Cos($y)) / (_Cosh(2 * $x) + Cos(2 * $y)), $Reps-1 ) Local $imag = Round( (-2 * _Sinh($x) * Sin($y)) / (_Cosh(2 * $x) + Cos(2 * $y)), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCsch() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCsch($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCsch($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") If $y = 0 And $x = 0 Then Return SetError(2,0,0) Local $real = Round( (2 * _Sinh($x) * Cos($y)) / (_Cosh(2 * $x) - Cos(2 * $y)), $Reps-1 ) Local $imag = Round( (-2 * _Cosh($x) * Sin($y)) / (_Cosh(2 * $x) - Cos(2 * $y)), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CCoth() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CCoth($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CCoth($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Local $x = DllStructGetData($cmp, "Real") Local $y = DllStructGetData($cmp, "Imag") If $y = 0 And $x = 0 Then Return SetError(2,0,0) Local $real = Round( (_Sinh(2 * $x)) / (_Cosh(2 * $x) - Cos(2 * $y)), $Reps-1 ) Local $imag = Round( (-Sin(2 * $y)) / (_Cosh(2 * $x) - Cos(2 * $y)), $Reps-1 ) Return _Cmplx($real, $imag) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CASinh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CASinh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CASinh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return _CLn(_CAdd($cmp, _CPow(_CAdd(_Cmplx(1,0), _CPow($cmp, 2)), 1/2))) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACosh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACosh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACosh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) Return _CLn(_CAdd($cmp, _CMul(_CPow(_CAdd($cmp, _Cmplx(1,0)), 1/2), _CPow(_CSub($cmp, _Cmplx(1,0)), 1/2)))) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CATanh() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CATanh($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CATanh($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) If DllStructGetData($cmp, "Real") = 1 and DllStructGetData($cmp, "Imag") = 0 Then Return SetError(2,0,0) Return _CMul(0.5, _CLn(_CDiv(_CAdd(_Cmplx(1, 0), $cmp), _CSub(_Cmplx(1, 0), $cmp)))) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACoth() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACoth($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACoth($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) If DllStructGetData($cmp, "Real") = 1 and DllStructGetData($cmp, "Imag") = 0 Then Return SetError(2,0,0) Return _CMul(0.5, _CLn(_CDiv(_CAdd($cmp, _Cmplx(1, 0)), _CSub($cmp, _Cmplx(1, 0))))) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CASech() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CASech($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CASech($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) If DllStructGetData($cmp, "Real") = 0 and DllStructGetData($cmp, "Imag") = 0 Then Return SetError(2,0,0) Return _CLn(_CAdd(_CMul(_CRoot(_CSub(_CDiv(_Cmplx(1,0), $cmp), _Cmplx(1,0)), 2), _CRoot(_CAdd(_CDiv(_Cmplx(1,0), $cmp), _Cmplx(1, 0)), 2)), _CDiv(_Cmplx(1,0), $cmp))) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CACsch() ; Description ...: Returns the logarithm of a complex number to an real exponent. ; Syntax ........: _CACsch($cmp, $n) ; Parameters ....: $cmp = complex number ; $m = float number, count value of the complex logarithm ; Return values .: On Success: = Returns the multiplication of complex numbers. ; On Failure: = Sets @Error and returns "", which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $cmp is not a number. ; Author ........: Strahleman ; Remarks .......: the complex number type is a two, double-floating type structure ; Example .......: ; =============================================================================================================================== Func _CACsch($cmp) If Not __Check($cmp) Then Return SetError(1,0,0) If DllStructGetData($cmp, "Real") = 0 and DllStructGetData($cmp, "Imag") = 0 Then Return SetError(2,0,0) Return _CLn(_CAdd(_CRoot(_CAdd(_Cmplx(1,0), _CDiv(_Cmplx(1, 0), _CPow($cmp, 2))), 2), _CDiv(_Cmplx(1, 0), $cmp))) EndFunc ; #FUNCTION# ===================================================================================================== ; Name ..........: _Sgn() ; Description ...: Returns the signum function. ; Syntax ........: _Sgn($x) ; Parameters ....: $x = a number ; Return values .: On Success: = Returns the signum. ; On Failure: = Sets @Error and returns 0, check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x is not a number. ; Author ........: Strahleman ; Remarks .......: if x < 0 then -1, x = 0 then 0, x > 0 then +1 ; Example .......: MsgBox(0x42040, "Basic Functions", "_Sgn( 10 ) = " & _Sgn(10) )) ; ================================================================================================================ Func _Sgn($x) If Not IsNumber($x) Then Return SetError(1,0,0) Local $s = 0 If $x < 0 Then $s = -1 ElseIf $x > 0 Then $s = 1 EndIf Return $s EndFunc ; #FUNCTION# ===================================================================================================== ; Name ..........: _Rat() ; Description ...: Returns the fraction of a rational number. ; Syntax ........: _Rat($x [, $p]) ; Parameters ....: $x = a number ; $p = an integer (presicion) [optional] ; Return values .: On Success: = Returns the fraction. ; On Failure: = Sets @Error and returns 0, check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x or $p is not a number. ; Author ........: Strahleman ; Remarks .......: Using continued fraction expansion. ; Example .......: $C = _rat(pi, 3) ; MsgBox(0x42040, "Basic Functions", "_Rat( " & $pi &", 3 ) = " & $C[0] & "/" & $C[1] ) ; ================================================================================================================ Func _Rat($x, $p=-1) If Not IsNumber($x) Or Not IsNumber($p) Then Return SetError(1,0,0) $p = Int($p) Local $B = _ContFrac($x, $p) Local $l = UBound($B) Local $Z[$l+1] Local $N[$l+1] Local $R[2] $Z[0]=1 $Z[1]=0 $N[0]=0 $N[1]=1 For $m=2 to $l $Z[$m]=$B[$m-1]*$Z[$m-1]+$Z[$m-2] $N[$m]=$B[$m-1]*$N[$m-1]+$N[$m-2] Next $R[0]=$Z[$l]+($B[0]*$N[$l]) $R[1]=$N[$l] Local $Y[Ubound($Z)][2] For $i = 0 to Ubound($Z)-1 $Y[$i][0] = $Z[$i] $Y[$i][1] = $N[$i] Next Return $R EndFunc ; #FUNCTION# ===================================================================================================== ; Name ..........: _ContFrac() ; Description ...: Returns the continued fraction of a rational number. ; Syntax ........: _ContFrac($x [, $p]) ; Parameters ....: $x = a number ; $p = an integer (presicion) [optional] ; Return values .: On Success: = Returns the continued fraction expansion. ; On Failure: = Sets @Error and returns 0, check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x or $p is not a number. ; Author ........: Strahleman ; Remarks .......: the calculation is determined by an iterative process. ; Example .......: $C = _ContFrac(pi, 3) ; _ArrayDisplay($C, "Basic Functions") ;requires Array.au3 ; ================================================================================================================ Func _ContFrac($x, $p=-1) If not IsNumber($x) or not IsNumber($p) Then Return SetError(1,0,0) Local $a=$x Local $k=0 Local $B[1] $B[0]=0 if $p=-1 Then $p=15 While ((1/$a*10^-10)>$meps and $k<=$p ) $k=$k+1 ReDim $B[$k] $B[$k-1] = Int($a) $a=(int(1/($a-$B[$k-1])*10^14))/10^14 WEnd Return $B EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Sinh() ; Description ...: Returns the standard position angle (in radians) to the point ($nX, $nY). ; Syntax ........: _Sinh($x) ; Parameters ....: $x = a number. ; Return values .: On Success: = Returns the sine function value. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x is not a number. ; Author ........: Strahleman ; Remarks .......: All angles are in radians. ; Example .......: MsgBox(0x42040, "Hyperbolic Trigonometric Functions", "_Sinh( $pi/6 ) = " & _Sinh( $pi/6 ) ) ; =============================================================================================================================== Func _Sinh($x) If Not IsNumber($x) Then If _CmplxCheck($x) Then Return _CSinh($x) Else Return SetError(1,0,0) EndIf EndIf Return Round((exp($x)-exp(-1*$x))/2, $Reps-1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Cosh() ; Description ...: Returns the standard position angle (in radians) to the point ($nX, $nY). ; Syntax ........: _Cosh($x) ; Parameters ....: $x = a number. ; Return values .: On Success: = Returns the sine function value. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x is not a number. ; Author ........: Strahleman ; Remarks .......: All angles are in radians. ; Example .......: MsgBox(0x42040, "Hyperbolic Trigonometric Functions", "_Cosh( $pi/6 ) = " & _Cosh( $pi/6 ) ) ; =============================================================================================================================== Func _Cosh($x) If Not IsNumber($x) Then If _CmplxCheck($x) Then Return _CCosh($x) Else Return SetError(1,0,0) EndIf EndIf Return Round((exp($x)+exp(-1*$x))/2, $Reps-1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ACosh() ; Description ...: Returns the standard position angle (in radians) to the point ($nX, $nY). ; Syntax ........: _ACosh($x) ; Parameters ....: $x = a number. ; Return values .: On Success: = Returns the sine function value. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x is not a number. ; Author ........: Strahleman ; Remarks .......: All angles are in radians. ; Example .......: ; =============================================================================================================================== Func _ACosh($y) If Not IsNumber($y) Then If _CmplxCheck($y) Then Return _CACosh($y) Else Return SetError(1,0,0) EndIf EndIf If $y < 1 Then Return SetError(2,0,0) EndIf Return Round(Log(Sqrt($y^2-1)+$y), $Reps-1) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ATanh() ; Description ...: Returns the standard position angle (in radians) to the point ($nX, $nY). ; Syntax ........: _ATanh($x) ; Parameters ....: $x = a number. ; Return values .: On Success: = Returns the sine function value. ; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first. ; @ERROR: = 0 = No error. ; 1 = $x is not a number. ; Author ........: Strahleman ; Remarks .......: All angles are in radians. ; Example .......: ; =============================================================================================================================== Func _ATanh($y) If Not IsNumber($y) Then If _CmplxCheck($y) Then Return _CATanh($y) Else Return SetError(1,0,0) EndIf EndIf If Abs($y)>1 Then Return SetError(2,0,0) EndIf Return 0.5*Log((1+$y)/(1-$y)) EndFunc