在 Golang 中查找复数的反双曲正切

go programmingserver side programmingprogramming

在数学中,复数的反双曲正切或反 tanh 定义为双曲正切函数的反函数。在 Golang 中,可以使用 cmplx.Atanh() 函数实现此函数。

语法

查找复数的反双曲正切的语法如下 −

func Atanh(z complex128) complex128

这里,z 是要计算其反双曲正切的复数,该函数以 complex128 值的形式返回复数的反双曲正切。

示例 1

假设我们有一个复数 z = 3 + 4i。我们可以使用 cmplx.Atanh() 函数找到这个复数的反双曲正切。

package main

import (
   "fmt"
   "math/cmplx"
)

func main() {
    // 创建复数
    z := complex(3, 4)
    
    // 查找复数的反双曲正切
    atanh := cmplx.Atanh(z)
    
    // 显示结果
    fmt.Println("的反双曲正切是", z, "is", atanh)
}

输出

(3+4i) 的反双曲正切为 (0.1175009073114339+1.4099210495965755i)

示例 2

假设我们有一个复数 z = -5 - 12i。我们可以使用 cmplx.Atanh() 函数找到该复数的反双曲正切。

package main

import (
   "fmt"
   "math/cmplx"
)

func main() {
    // 创建一个复数
    z := complex(0, 1)
    
    // 求复数的反双曲正切
    atanh := cmplx.Atanh(z)
    
    // 显示结果
    fmt.Println("的反双曲正切是", z, "is", atanh)
}

输出

(0+1i) 的反双曲正切是 (0+0.7853981633974483i)

结论

在本文中,我们学习了如何使用 cmplx.Atanh() 函数在 Golang 中求复数的反双曲正切。我们还看了一些示例来了解其实现。


相关文章