Golang 查找复数的余切值

Golang 查找复数的余切值

Go语言提供了cmplx包的基本常量和数学函数,可以帮助处理复数。您可以使用math/cmplx包提供的Cot()函数查找指定复数的余切值。因此,您需要在程序中使用import关键字添加math/cmplx包以访问Cot()函数。

语法:

func Cot(y complex128) complex128

让我们通过给定的示例来讨论这个概念:

示例1:

// Golang程序来说明如何查找给定复数的余切值
  
package main
  
import (
    "fmt"
    "math/cmplx"
)
  
// 主函数
func main() {
  
    // 查找特定复数的余切值
    // 使用Cot()函数
    res_1 := cmplx.Cot(2 + 5i)
    res_2 := cmplx.Cot(-1 + 8i)
    res_3 := cmplx.Cot(-1 - 7i)
  
    // 显示结果
    fmt.Println("结果1:", res_1)
    fmt.Println("结果2:", res_2)
    fmt.Println("结果3:", res_3)
} 

输出:

结果1: (-6.871348192386196e-05-0.9999406486514081i)
结果2: (-2.0465587043065668e-07-0.9999999063376698i)
结果3: (-1.5122128026576863e-06+0.9999993079230043i)

示例2:

// Golang程序来说明如何查找给定复数的余切值
  
package main
  
import (
    "fmt"
    "math/cmplx"
)
  
// 主函数
func main() {
  
    cnumber_1 := complex(1, 2)
    cnumber_2 := complex(3, 6)
  
    // 查找余切值
    cvalue_1 := cmplx.Cot(cnumber_1)
    cvalue_2 := cmplx.Cot(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:  (1+2i)
余切值1:  (0.03279775553375259-0.984329226458191i)
复数2:  (3+6i)
余切值2:  (-3.433616824537947e-06-1.0000117990439865i)
和 :  (0.03279432191692805-1.9843410255021774i)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程