El lenguaje Go brinda soporte incorporado para constantes básicas y funciones matemáticas para números complejos con la ayuda del paquete cmplx. Puede encontrar el logaritmo decimal del número complejo especificado con la ayuda de la función Log10() proporcionada por el paquete math/cmplx. Por lo tanto, debe agregar un paquete matemático/cmplx en su programa con la ayuda de la palabra clave de importación para acceder a la función Log10().
Sintaxis:
func Log10(y complex128) complex128
Ejemplo 1:
// Golang program to illustrate how to find the // decimal logarithm of the given complex number package main import ( "fmt" "math/cmplx" ) // Main function func main() { // Finding decimal logarithm of // the specified complex number // Using Log10() function res_1 := cmplx.Log10(1i) res_2 := cmplx.Log10(-4 + 12i) res_3 := cmplx.Log10(-3 - 9i) // Displaying the result fmt.Printf("Result 1: %.1f", res_1) fmt.Printf("\nResult 2: %.1f", res_2) fmt.Printf("\nResult 3: %.1f", res_3) }
Producción:
Result 1: (0.0+0.7i) Result 2: (1.1+0.8i) Result 3: (1.0-0.8i)
Ejemplo 2:
// Golang program to illustrate how to find the // decimal logarithm of the given complex number package main import ( "fmt" "math/cmplx" ) // Main function func main() { cnumber_1 := complex(0, 2) cnumber_2 := complex(4, 6) // Finding decimal logarithm cvalue_1 := cmplx.Log10(cnumber_1) cvalue_2 := cmplx.Log10(cnumber_2) // Sum of the given values res := cvalue_1 + cvalue_2 // Displaying results fmt.Println("Complex Number 1: ", cnumber_1) fmt.Printf("Decimal logarithm 1: %.1f", cvalue_1) fmt.Println("\nComplex Number 2: ", cnumber_2) fmt.Printf("Decimal logarithm 2: %.1f ", cvalue_2) fmt.Printf("\nSum : %.1f", res) }
Producción:
Complex Number 1: (0+2i) Decimal logarithm 1: (0.3+0.7i) Complex Number 2: (4+6i) Decimal logarithm 2: (0.9+0.4i) Sum : (1.2+1.1i)
Publicación traducida automáticamente
Artículo escrito por Kirti_Mangal y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA