Golang 找到复杂数的双曲正切值
Go语言通过cmplx包提供了基本常量和数学函数的内置支持,用于复杂数。使用math/cmplx包提供的Tanh()函数可以找到指定复数的双曲正切值。因此,您需要使用import关键字将math/cmplx包添加到您的程序中以访问Tanh()函数。
语法:
func Tanh(y complex128) complex128
让我们通过给定的示例来讨论这个概念:
示例1:
// Golang程序以说明找到指定复杂数的双曲正切值
package main
import (
"fmt"
"math/cmplx"
)
// 主函数
func main() {
// 找到该复杂数的双曲正切值
// 使用Tanh()函数
res_1 := cmplx.Tanh(1 + 5i)
res_2 := cmplx.Tanh(-2 + 8i)
res_3 := cmplx.Tanh(-1 - 2i)
// 显示结果
fmt.Println("Result 1: ", res_1)
fmt.Println("Result 2: ", res_2)
fmt.Println("Result 3: ", res_3)
}
输出:
Result 1: (1.2407479829240697-0.1861094776473042i)
Result 2: (-1.0356479469632376-0.010925884335752532i)
Result 3: (-1.16673625724092+0.24345820118572523i)
示例2:
// Golang程序以说明找到指定复杂数的双曲正切值
package main
import (
"fmt"
"math/cmplx"
)
// 主函数
func main() {
cnumber_1 := complex(0, 2)
cnumber_2 := complex(4, 6)
// 找到该复杂数的双曲正切值
cvalue_1 := cmplx.Tanh(cnumber_1)
cvalue_2 := cmplx.Tanh(cnumber_2)
// 两个双曲正切值的总和
res := cvalue_1 + cvalue_2
// 显示结果
fmt.Println("复杂数 1: ", cnumber_1)
fmt.Println("双曲正切 1: ", cvalue_1)
fmt.Println("复杂数 2: ", cnumber_2)
fmt.Println("双曲正切 2: ", cvalue_2)
fmt.Println("和 : ", res)
}
输出:
复杂数 1: (0+2i)
双曲正切1: (0-2.185039863261519i)
复杂数 2: (4+6i)
双曲正切 2: (0.9994339325466381-0.0003597965782916252i)
和 : (0.9994339325466381-2.1853996598398107i)