在 Golang 中查詢複數的反正切


三角函式廣泛應用於數學、物理、工程和許多其他領域。反三角函式是三角函式的反函式,它們用於在已知直角三角形兩邊之比的情況下求角度。本文將討論如何在 Golang 中查詢複數的反正切。

查詢複數的反正切

要在 Golang 中查詢複數的反正切,我們可以使用 math/cmplx 包中的 Atan() 函式。Atan() 函式以複數作為引數,並返回該複數的反正切。

語法

Atan() 函式的語法如下:

func Atan(x complex128) complex128

這裡,x 是我們要查詢其反正切的複數。

示例 1:查詢複數的反正切

讓我們使用 Atan() 函式查詢複數的反正切。

package main

import (
   "fmt"
   "math/cmplx"
)

func main() {
   // Creating a complex number
   z := complex(3, 4)
   
   // Finding the inverse tangent of the complex number
   atan := cmplx.Atan(z)
   
   // Displaying the result
   fmt.Println("Inverse Tangent of", z, "is", atan)
}

輸出

Inverse Tangent of (3+4i) is (1.4483069952314644+0.15899719167999918i)

示例 2:查詢負複數的反正切

讓我們使用 Atan() 函式查詢負複數的反正切。

package main

import (
   "fmt"
   "math/cmplx"
)

func main() {
   // Creating a complex number
   z := complex(-3, -4)
   
   // Finding the inverse tangent of the complex number
   atan := cmplx.Atan(z)
   
   // Displaying the result
   fmt.Println("Inverse Tangent of", z, "is", atan)
}

輸出

Inverse Tangent of (-3-4i) is (-1.4483069952314644-0.15899719167999918i)

示例 3:查詢純虛數的反正切

讓我們使用 Atan() 函式查詢純虛數的反正切。

package main

import (
   "fmt"
   "math/cmplx"
)
   
func main() {
   // Creating a complex number
   z := complex(0, 5)
   
   // Finding the inverse tangent of the complex number
   atan := cmplx.Atan(z)
   
   // Displaying the result
   fmt.Println("Inverse Tangent of", z, "is", atan)
}

輸出

Inverse Tangent of (0+5i) is (-1.5707963267948968+0.2027325540540822i)

示例 4:查詢虛數的反正切

讓我們使用 Atan() 函式查詢虛數的反正切。

package main

import (
   "fmt"
   "math/cmplx"
)
   
func main() {
   // Creating a complex number
   z := complex(-2, -1)
   
   // Finding the inverse tangent of the complex number
   atan := cmplx.Atan(z)
   
   // Displaying the result
   fmt.Println("Inverse Tangent of", z, "is", atan)
}

輸出

Inverse Tangent of (-2-1i) is (-1.1780972450961724-0.17328679513998632i)

結論

反三角函式在解決複雜的數學問題中很有用,Golang 提供了幾個內建函式來查詢複數的反正弦、反餘弦、反正切和反雙曲函式。這些函式是 math/cmplx 包的一部分,可以在 Golang 程式中輕鬆使用。

在處理複數時,請務必記住,這些函式的結果也可能是複數,而不總是實數。因此,務必相應地處理這些函式的輸出。

總的來說,能夠在 Golang 中查詢複數的反三角函式使其成為處理複數的數學家、工程師和科學家的強大工具。

更新於: 2023 年 4 月 17 日

97 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告