komplexe Zahlen (UDF)

  • Inspiriert von der "Geburtstagsansprache" von Oscar poste ich jetzt einfach mal meine UDF für komplexe Zahlen, an der ich in den letzten Wochen gearbeitet habe, vielleicht findet ja jemand Verwendung dafür. :D

    Verwendung:
    Momentan stehen neben den Grundrechenarten +, -, *, / und ^ die Funktionen Sqrt, Exp, Log, Sin, Cos, Tan, Cot, Sec, Csc zur Verfügung. Um diese von den "normalen" Funktionen unterscheiden zu können beginnen sie mit einem c, aus Sqrt(-1) wird also cSqrt(-1). Die Parameter der Funktionen sind eigentlich mit c(Realteil, Imaginärteil) erstellte komplexe Zahlen (Arrays), man kann aber auch problemlos reelle Zahlen als Parameter übergeben (wie in dem Beispiel im vorherigen Satz).

    UDF
    [autoit]

    #include-once

    [/autoit] [autoit][/autoit] [autoit]

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Complex Numbers UDF by James (autoit.de) ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    [/autoit] [autoit][/autoit] [autoit]

    Func c($a=0, $b=1)
    Local $c[2] = [$a, $b]
    Return $c
    EndFunc
    Func cTest(ByRef $cmplx)
    If (Not IsArray($cmplx)) Then $cmplx = c(Number($cmplx, 3), 0)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cToString($c)
    cTest($c)
    If ($c[1] = 0) Then Return $c[0]
    If ($c[0] = 0) Then
    If ($c[1] = 1) Then Return "i"
    If ($c[1] = -1) Then Return "-i"
    Return $c[1] & "*i"
    EndIf
    If ($c[1] < 0) Then
    If ($c[1] = -1) Then Return $c[0] & " - i"
    Return $c[0] & " - " & Abs($c[1]) & "*i"
    EndIf
    If ($c[1] = 1) Then Return $c[0] & " + i"
    If ($c[1] = -1) Then Return $c[0] & " - i"
    Return $c[0] & " + " & $c[1] & "*i"
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cArg($c)
    cTest($c)
    Local Static $pi = ATan(1)*4
    If ($c[0] > 0) Then Return ATan($c[1]/$c[0])
    If ($c[0] < 0) And ($c[1] >= 0) Then Return ATan($c[1]/$c[0])+$pi
    If ($c[0] < 0) And ($c[1] < 0) Then Return ATan($c[1]/$c[0])-$pi
    If ($c[0] = 0) And ($c[1] > 0) Then Return $pi/2
    If ($c[0] = 0) And ($c[1] < 0) Then Return -$pi/2
    Return SetError(1, 0, "-1.#IND")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cAbs($c)
    cTest($c)
    Return Sqrt($c[0]^2 + $c[1]^2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cAdd($a, $b)
    cTest($a)
    cTest($b)
    Local $c[2] = [ $a[0]+$b[0] , $a[1]+$b[1] ]
    Return $c
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cSub($a, $b)
    cTest($a)
    cTest($b)
    Local $c[2] = [ $a[0]-$b[0] , $a[1]-$b[1] ]
    Return $c
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cMul($a, $b)
    cTest($a)
    cTest($b)
    Local $c[2] = [ $a[0]*$b[0]-$a[1]*$b[1] , $a[1]*$b[0]+$a[0]*$b[1] ]
    Return $c
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cDiv($a, $b)
    cTest($a)
    cTest($b)
    Local $c[2] = [ ($a[0]*$b[0]+$a[1]*$b[1])/($b[0]^2+$b[1]^2) , ($a[1]*$b[0]-$a[0]*$b[1])/($b[0]^2+$b[1]^2) ]
    Return $c
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cSqrt($c)
    cTest($c)
    Local $sqrt[2]
    If ($c[1] = 0) Then
    If ($c[0] >= 0) Then
    $sqrt[0] = Sqrt($c[0])
    $sqrt[1] = 0
    Else
    $sqrt[0] = 0
    $sqrt[1] = Sqrt(Abs($c[0]))
    EndIf
    Else
    $sqrt[0] = Sqrt(($c[0]+cAbs($c))/2)
    $sqrt[1] = _sgn($c[1])*Sqrt((-$c[0]+cAbs($c))/2)
    EndIf
    Return $sqrt
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _sgn($x)
    Return ($x > 0) - ($x < 0)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cExp($_)
    cTest($_)
    Return cMul(c(Exp($_[0]), 0), c(Round(Cos($_[1]), 15), Round(Sin($_[1]), 15)))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cLog($_)
    cTest($_)
    Return c(Log(cAbs($_)), cArg($_))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cPow($a, $b)
    cTest($a)
    cTest($b)
    Return cExp(cMul($b, cLog($a)))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cSin($_)
    cTest($_)
    Return c(Sin($_[0])*_cosh($_[1]), Cos($_[0])*_sinh($_[1]))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cCos($_)
    cTest($_)
    Return c(Cos($_[0])*_cosh($_[1]), -Sin($_[0])*_sinh($_[1]))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cTan($c)
    cTest($c)
    Return cDiv(cSin($c), cCos($c))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cCot($c)
    cTest($c)
    Return cDiv(cCos($c), cSin($c))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cSec($c)
    cTest($c)
    Return cDiv(1, cCos($c))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cCsc($c)
    cTest($c)
    Return cDiv(1, cSin($c))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _sinh($x)
    Return (Exp($x)-Exp(-$x))/2
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _cosh($x)
    Return (Exp($x)+Exp(-$x))/2
    EndFunc

    [/autoit]
  • Moin,

    Ich finde die Sache sehr schön, auch wenn ich selbst noch nach einer Verwendung suchen muss :D

    Spoiler anzeigen

    konnte mich nicht bremsen als die Funktion mit den vielen Returns aufgetaucht ist^^

    [autoit]

    Func cToStr($c) ; Beta mit exp ? #t : #f
    Return IsArray($c)?$c[1]=0?$c[0]:$c[0]=0 _
    ?Abs($c[1])&'*i'='1*i'?StringLeft($c[1], _
    1*($c[1]<0))&'i':$c[1]&'i':$c[1]<0?$c[1] _
    =-1?$c[0]&' - i':$c[0]&' - '&Abs($c[1])& _
    '*i':$c[1]=1?$c[0]&' + i':$c[1]=-1?$c[0] _
    &' - i':$c[0]&' + '&$c[1]&'*i':cToStr(c( _
    Number($c,3),0))
    EndFunc

    [/autoit]

    lg
    M

  • So kann man das natürlich auch machen. :D

    Mit Structs statt Arrays und dem ternären Operator in der cToString Funktion würde die UDF um einiges besser aussehen, aber bis zur nächsten Stable verzichte ich darauf lieber... Über den Sinn lässt sich natürlich auch streiten, aber vielleicht will ja hier jemand die Lösungsformel für Polynome 3. Grades in AutoIt implementieren. :D

  • Dann stell mal schnell in Trac einen Feature Request ;)

  • Hallo,

    also komplexe Zahlen sind in der Elektrotechnik und im Maschinenbau extrem wichtig. Und wer schon einmal probiert hat, Berechnungen für die Wechselstromtechnik zu programmieren, wird um die komplexen Zahlen gar nicht herum kommen. Mir ging es ähnlich, deshalb hab ich auch eine UDF für komplexe Zahlen entwickelt. allerdings hab ich auch structs verwendet. Aber am Ende muss jeder selber entscheiden was und wie er es nutzen möchte.

    UDF Complex.au3
    [autoit]


    #cs

    [/autoit] [autoit][/autoit] [autoit]

    #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-07-02
    ================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    Func __Reps()
    Return Round(Abs(Log(__Machine_Epsilon())/log(10)),0)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #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
    SetError(1)
    Return False
    EndIf
    Local $cmpReal = DllStructGetData($cmp, "Real")
    If @error Then
    SetError(1)
    Return False
    EndIf
    Local $cmpImag = DllStructGetData($cmp, "Imag")
    If @error Then
    SetError(1)
    Return False
    EndIf
    If Not( $cmpSize = 16 And IsNumber($cmpReal) And IsNumber($cmpImag) ) Then
    SetError(1)
    Return False
    EndIf
    Return True
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    if IsNumber($cmp) Then
    $cmp = _Cmplx($cmp)
    Else
    SetError(1)
    return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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
    SetError(1)
    Return 0
    EndIf
    Local $cmp = DllStructCreate("double Real;double Imag")
    DllStructSetData($cmp, "Real", $real)
    DllStructSetData($cmp, "Imag", $imag)
    Return $cmp
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    SetError(1)
    Return 0
    EndIf
    Return Sqrt(DllStructGetData($cmp, "Real")^2 + DllStructGetData($cmp, "Imag")^2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    SetError(1)
    Return 0
    EndIf
    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
    SetError(2)
    Return 0
    EndIf
    EndSelect
    SetError(1)
    Return 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    SetError(1)
    Return 0
    EndIf
    Return DllStructGetData($cmp, "Real")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    SetError(1)
    Return 0
    EndIf
    Return DllStructGetData($cmp, "Imag")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    Return _Cmplx($cmp,0)
    EndIf
    SetError(1)
    Return 0
    EndIf
    Return _Cmplx(DllStructGetData($cmp, "Real"), -1 * DllStructGetData($cmp, "Imag"))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp1) Then
    If IsNumber($cmp1) Then
    $cmp1 = _Cmplx($cmp1, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not _CmplxCheck($cmp2) Then
    If IsNumber($cmp2) Then
    $cmp2 = _Cmplx($cmp2, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp1) Then
    If IsNumber($cmp1) Then
    $cmp1 = _Cmplx($cmp1, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not _CmplxCheck($cmp2) Then
    If IsNumber($cmp2) Then
    $cmp2 = _Cmplx($cmp2, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp1) Then
    If IsNumber($cmp1) Then
    $cmp1 = _Cmplx($cmp1, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not _CmplxCheck($cmp2) Then
    If IsNumber($cmp2) Then
    $cmp2 = _Cmplx($cmp2, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp1) Then
    If IsNumber($cmp1) Then
    $cmp1 = _Cmplx($cmp1, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not _CmplxCheck($cmp2) Then
    If IsNumber($cmp2) Then
    $cmp2 = _Cmplx($cmp2, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If DllStructGetData($cmp2, "Real") = 0 and DllStructGetData($cmp2, "Imag") = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not IsNumber($n) Then
    SetError(1)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not IsNumber($n) or Not IsNumber($m) Then
    SetError(1)
    Return 0
    EndIf
    Local $R = _Rat($n)
    If $m >= $R[0] Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If Not IsNumber($m) Then
    SetError(1)
    Return 0
    EndIf
    Local $real = Round(Log(_CAbs($cmp)),$Reps-1)
    Local $imag = Round(_CArg($cmp)+(2*$m*$pi),$Reps-1)
    Return _Cmplx($real, $imag)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Local $x = DllStructGetData($cmp, "Real")
    Local $y = DllStructGetData($cmp, "Imag")
    If $y = 0 And $x = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Local $x = DllStructGetData($cmp, "Real")
    Local $y = DllStructGetData($cmp, "Imag")
    If $y = 0 And $x = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    $cmp = _CDiv(1, $cmp)
    if @error Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    $cmp = _CDiv(1, $cmp)
    if @error Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Local $x = DllStructGetData($cmp, "Real")
    Local $y = DllStructGetData($cmp, "Imag")
    If $y = 0 And $x = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Local $x = DllStructGetData($cmp, "Real")
    Local $y = DllStructGetData($cmp, "Imag")
    If $y = 0 And $x = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Return _CLn(_CAdd($cmp, _CPow(_CAdd(_Cmplx(1,0), _CPow($cmp, 2)), 1/2)))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    Return _CLn(_CAdd($cmp, _CMul(_CPow(_CAdd($cmp, _Cmplx(1,0)), 1/2), _CPow(_CSub($cmp, _Cmplx(1,0)), 1/2))))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If DllStructGetData($cmp, "Real") = 1 and DllStructGetData($cmp, "Imag") = 0 Then
    SetError(2)
    Return 0
    EndIf
    Return _CMul(0.5, _CLn(_CDiv(_CAdd(_Cmplx(1, 0), $cmp), _CSub(_Cmplx(1, 0), $cmp))))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If DllStructGetData($cmp, "Real") = 1 and DllStructGetData($cmp, "Imag") = 0 Then
    SetError(2)
    Return 0
    EndIf
    Return _CMul(0.5, _CLn(_CDiv(_CAdd($cmp, _Cmplx(1, 0)), _CSub($cmp, _Cmplx(1, 0)))))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If DllStructGetData($cmp, "Real") = 0 and DllStructGetData($cmp, "Imag") = 0 Then
    SetError(2)
    Return 0
    EndIf
    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

    [/autoit] [autoit][/autoit] [autoit]

    ; #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 _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf
    If DllStructGetData($cmp, "Real") = 0 and DllStructGetData($cmp, "Imag") = 0 Then
    SetError(2)
    Return 0
    EndIf
    Return _CLn(_CAdd(_CRoot(_CAdd(_Cmplx(1,0), _CDiv(_Cmplx(1, 0), _CPow($cmp, 2))), 2), _CDiv(_Cmplx(1, 0), $cmp)))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit]


    PS: Die Erklärungen/Kommentare sind nicht vollständig.

    Gruß der Strahleman 8)

    Wenn denn alles so einfach wäre wie

    [autoit]

    "Autoit"

    [/autoit]

    meine UDFs
    Math2

    Wichtige Threads
    Math2

    Einmal editiert, zuletzt von Strahleman (11. Dezember 2013 um 10:15)

    • Offizieller Beitrag

    Ah.. Komplexe Zahlen, das hatte ich in der Abiturstufe als Kurs belegt.

    Feine Lösungen.
    Strahlemann, deines erschlägt einen ja fast mit seiner Komplexität - Respekt :thumbup:
    Eines mal als Tipp von einem alten Funktions-Junkie ;)
    - SetError und in der Folgezeile erst den Return ist selten erforderlich
    Da SetError als 3-ten Parameter einen Returnwert enthält, funktioniert "Return SetError(iErr, iExt, iReturn)" super.
    - Gerade bei solch umfangreicher Funktionssammlung nach Vereinfachungen schauen. Du verwendest in der Mehrzahl der Funktionen

    [autoit]

    If Not _CmplxCheck($cmp) Then
    If IsNumber($cmp) Then
    $cmp = _Cmplx($cmp, 0)
    Else
    SetError(1)
    Return 0
    EndIf
    EndIf

    [/autoit]


    Was hältst du hier von:

    [autoit]

    ; == dafür nur:
    If Not __Check($cmp) Then Return SetError(1,0,0)

    Func __Check(ByRef $_cmp)
    If Not _CmplxCheck($_cmp) Then
    If Not IsNumber($_cmp) Then Return False
    $_cmp = _Cmplx($_cmp, 0)
    EndIf
    Return True
    EndFunc

    [/autoit]


    Spart dir 7 Zeilen Code je Aufruf. Bei dem Umfang haut das ganz schön rein. ;)

  • Hi BugFix,

    ja danke für die Hinweise, die Änderungen werde ich auf jeden Fall aufnehmen. Vereinfachen ist immer so eine lästige Arbeit - vor allem wenn man sich freut, dass die Funktionen endlich laufen ;)
    Mal sehen wann ich Zeit hab das einzupflegen. Dann werde ich die neue UDF auch nochmal einstellen.

    Gruß der Strahleman 8)

    Wenn denn alles so einfach wäre wie

    [autoit]

    "Autoit"

    [/autoit]

    meine UDFs
    Math2

    Wichtige Threads
    Math2

  • Es hat mir keine Ruhe gegeben.
    Ich wollte die UDF natürlich auch so einfach wie möglich gestalten, somit hier jetzt die vereinfachte Version.
    Außerdem ist mir aufgefallen, dass ich auf eine andere UDF verweise bzw. auf Funktionen aus einer anderen UDF. Hab die benötigten Funktionen jetzt direkt in die Complex-UDF eingegeben.

    Falls Interesse besteht stelle ich die Datei und eine Beispieldatei zum Download bereit:
    Complex
    autoit.de/wcf/attachment/23748/

    Complex Beispiele
    autoit.de/wcf/attachment/23747/

  • allerdings hab ich auch structs verwendet.

    Das bietet sich natürlich besonders an, wenn man eine der aktuellen Beta-Versionen benutzt:

    [autoit]

    $c = cmplx(1, 2)
    $a = $c.re
    $b = $c.im

    [/autoit]


    Bei meiner UDF für Vektoren (welche ich bei Gelegenheit vervollständigen und posten werde) habe ich das auch so gemacht, da es eigentlich gar nicht übersichtlicher geht. Ist dann aber leider auf die Beta beschränkt.

    Du verwendest in der Mehrzahl der Funktionen [...]
    Spart dir 7 Zeilen Code je Aufruf. Bei dem Umfang haut das ganz schön rein.

    Cool, dann habe ich sogar intuitiv mal was richtig gemacht. :D

  • Nach einer anständigen Analyse der ToString Funktion konnte ich sie mal vernünftig verkürzen :D
    Die alte (aus meinem ersten Post) hat 249 Byte, die neue noch 132 ;)

    &quot;Zauberei&quot;
    [autoit]

    Func cToStr($c)
    Return (cTest($c)?'':(($c[0])?$c[0]:(($c[1])?'' _
    :0))&(($c[1])?(($c[0])?(($c[1]>0)?' + ':' - '): _
    '')&((Abs($c[1])=1)?'i':Abs($c[1])&'*i'):''))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cToStr($c)
    Return (cTest($c)?'':(($c.re)?$c.re:(($c.im)?'' _
    :0))&(($c.im)?(($c.re)?(($c.im>0)?' + ':' - '): _
    '')&((Abs($c.im)=1)?'i':Abs($c.im)&'*i'):''))
    EndFunc

    [/autoit]

    Man sieht: nahezu keinerlei Redundanzen, eine viel kürzere Version ist also nicht möglich :)

    &quot;Test&quot;
    [autoit]


    Local $a[9] = [c(0, 0), c(1, 1), c(2, 2), c(-1, -1), c(-2, -2), c(1, -1), c(-1, 1), c(0, 2), c(1, 0)]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To UBound($a) - 1 Step 1
    ConsoleWrite(cToString($a[$i]) & @CRLF)
    ConsoleWrite(cToStr($a[$i]) & @CRLF)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Func cToStr($c)
    Return (cTest($c)?'':(($c.re)?$c.re:(($c.im)?'' _
    :0))&(($c.im)?(($c.re)?(($c.im>0)?' + ':' - '): _
    '')&((Abs($c.im)=1)?'i':Abs($c.im)&'*i'):''))
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func cToString($c)
    cTest($c)
    If ($c.im = 0) Then Return $c.re
    If ($c.re = 0) Then
    If ($c.im = 1) Then Return "i"
    If ($c.im = -1) Then Return "-i"
    Return $c.im & "*i"
    EndIf
    If ($c.im < 0) Then
    If ($c.im = -1) Then Return $c.re & " - i"
    Return $c.re & " - " & Abs($c.im) & "*i"
    EndIf
    If ($c.im = 1) Then Return $c.re & " + i"
    If ($c.im = -1) Then Return $c.re & " - i"
    Return $c.re & " + " & $c.im & "*i"
    EndFunc ;==>cToString

    [/autoit] [autoit][/autoit] [autoit]

    Func c($a = 0, $b = 1)
    Local $c = DllStructCreate('double re;double im')
    $c.re = $a
    $c.im = $b
    Return $c
    EndFunc ;==>c

    [/autoit] [autoit][/autoit] [autoit]

    Func cTest(ByRef $c)
    If (Not IsDllStruct($c)) Then $c = c(Number($c, 3), 0)
    EndFunc ;==>cTest

    [/autoit]


    Sinnlose Optimierungen FTW !
    lg
    M

  • Hey James,
    deine komplexe Zahlen UDF erinnerte mich direkt an ein vor langer Zeit geschriebenes Programm von mir über die Mandelbrotmenge.

    Da ich seit langer Zeit kein AutoIt mehr angerührt habe kitzelte es mir doch ein bisschen in den Fingerspitzen und ich habe das ganze mal als Funktion mit deinen Funktionen umgesetzt:

    [autoit]


    ;Parameter:
    ; c - Komplexe Zahl (Koordinaten die geprüft werden sollen)
    ; max - Maximale Anzahl an Iterationen (bzw in dem Fall Rekursionen)
    ; zOld - Nicht verändern
    ; actual - Nicht verändern
    Func Mandelbrot($c, $max = 20, $zOld = 0, $actual = 0)
    If ($max >= $actual) Then
    $zActual = cAdd(cMul($zOld, $zOld), $c)
    If (cAbs($zActual) < 2) Then
    Return Mandelbrot($c, $max, $zActual, $actual + 1)
    Else
    Return cAbs($zActual)
    EndIf
    Else
    Return cAbs($zOld)
    EndIf
    EndFunc ;==>Mandelbrot

    [/autoit]

    Normalerweise ist die Berechnung Iterativ, da ich aber schulisch (in Delphi :thumbdown: ) so oft rekursiv arbeite habe ich es auch mal hier rekursiv versucht und geschafft :D.
    Lange Rede kurzer Sinn. Die Funktion prüft ob eine Koordinate im komplexen Koordinatensystem (oder wie man das nannte) auch wirklich zur Mandelbrotmenge gehört.
    MfG - Xorianator

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • Sehr schön.
    Gut, dass du mich daran erinnert hast, das wollte ich auch schon lange mal programmieren.

    Ich habe das jetzt einfach mal als iterative Funktion umgesetzt und ein bisschen GDI+ drumherum gepackt. Die Performance ist wirklich schlecht, aber das kann man ja bei Gelegenheit ändern.

    Spoiler anzeigen
    [autoit]

    #NoTrayIcon
    #include <GDIPlus.au3>
    #include "cmplx.au3"

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    Local $GUI, $Graphics, $Bitmap, $Buffer

    [/autoit] [autoit][/autoit] [autoit]

    AutoItSetOption("GUIOnEventMode", 1)
    $GUI = GUICreate("Mandelbrot", 400, 300)
    $Graphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics(400, 300, $Graphics)
    $Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
    _GDIPlus_GraphicsClear($Buffer, 0xFFFFFFFF)
    GUISetOnEvent(-3, "Quit")
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    For $y = -100 To 100 Step 1
    For $x = -200 To 100
    If Mandelbrot(c($x/100, $y/100), 20) Then
    _GDIPlus_GraphicsFillRect($Buffer, $x+250, $y+150, 1, 1)
    _GDIPlus_GraphicsDrawImageRect($Graphics, $Bitmap, 0, 0, 400, 300)
    EndIf
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until False
    Func Quit()
    _GDIPlus_GraphicsDispose($Buffer)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_GraphicsDispose($Graphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Mandelbrot($c, $n=20)
    Local $z = $c,$i
    For $i = 1 To $n
    $z = cAdd(cPow($z, 2), $c)
    If (cAbs($z) > 2) Then Return False
    Next
    Return True
    EndFunc

    [/autoit]
  • Die Performance erinnert mich ja schon fast an das Programm was ich vor 2 Jahren geschrieben habe :D
    Aber schön gemacht, auf jedenfall ;)

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal