La función complx.Polar() en Golang devuelve el valor absoluto r y la fase θ de x. La fase θ estará en el rango [-Pi, Pi].
Sintaxis:
func Polar(x complex128) (r, θ float64)
Aquí, x es un número complejo.
Valor devuelto: El valor devuelto está en el rango [-Pi, Pi].
Ejemplo 1:
// Golang program to illustrate // the complx.Polar() Function package main // importing fmt, math and math/cmplx import ( "fmt" "math" "math/cmplx" ) // Calling Main func main() { // getting the r and theta value r, theta := cmplx.Polar(7i) // calculate the value in Pi format. p := theta/math.Pi // printing the values r and p. fmt.Printf("rValue: %.1f, pValue: %.1f*Pi", r, p) }
Producción:
rValue: 7.0, pValue: 0.5*Pi
Ejemplo 2:
// Golang program to illustrate // the complx.Polar() Function package main // importing fmt, math and math/cmplx import ( "fmt" "math" "math/cmplx" ) // Calling Main func main() { // We can create a complex number like this also. n := complex(5, 6) // getting the r and theta value of complex number 5 + 6i r, theta := cmplx.Polar(n) // calculate the value in Pi format. p := theta/math.Pi // printing the values r and p. fmt.Printf("rValue: %.1f, pValue: %.1f*Pi", r, p) }
Producción:
rValue: 7.8, pValue: 0.3*Pi
Publicación traducida automáticamente
Artículo escrito por PranchalKatiyar y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA