Golang complx.Rect()函数例子

Golang complx.Rect()函数例子

complx.Rect()函数 是 Golang 中的一个方法,它基于极坐标 r,θ 返回一个带有复数的 x 值。 它需要输入浮点值并返回一个复数。 该方法属于复数包。

语法:

func Rect(r,θ float64) complex128;

这里 r 和 θ 是包含 float64 的实部和虚部的复数。

返回值:

它返回一个坐标为(r, θ)的复数。

例子 1:

// Golang程序演示
// complx.Rect()函数
  
package main

// 导入 fmt 和 math/cmplx
import (
"fmt"
"math/cmplx"
)

// 调用主方法
func main () {

// 使用函数
fmt.Printf ("%.1f", cmplx.Rect (5, 45))
} 

输出:

(2.6+4.3i)

例子 2:

// Golang程序演示
// complx.Rect()函数
  
package main
  
// 导入 fmt、math 和 math/cmplx
import (
"fmt"
"math"
"math/cmplx"
)

// 调用主方法
func main() {
 
// 使用函数
fmt.Printf("%.1f,", cmplx.Rect(5, 4*math.Pi)) 
fmt.Printf("%.1f", cmplx.Rect(5, 90))
} 

输出:

(5.0-0.0i),(-2.2+4.5i)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程