Finding the Decimal Logarithm of Complex Number in Golang
Last Updated :
27 Mar, 2020
Go language provides inbuilt support for basic constants and mathematical functions for complex numbers with the help of the cmplx package. You are allowed to find the decimal logarithm of the specified complex number with the help of Log10() function provided by the math/cmplx package. So, you need to add a math/cmplx package in your program with the help of the import keyword to access the Log10() function.
Syntax:
func Log10(y complex128) complex128
Example 1:
package main
import (
"fmt"
"math/cmplx"
)
func main() {
res_1 := cmplx.Log10(1i)
res_2 := cmplx.Log10(-4 + 12i)
res_3 := cmplx.Log10(-3 - 9i)
fmt.Printf( "Result 1: %.1f" , res_1)
fmt.Printf( "\nResult 2: %.1f" , res_2)
fmt.Printf( "\nResult 3: %.1f" , res_3)
}
|
Output:
Result 1: (0.0+0.7i)
Result 2: (1.1+0.8i)
Result 3: (1.0-0.8i)
Example 2:
package main
import (
"fmt"
"math/cmplx"
)
func main() {
cnumber_1 := complex(0, 2)
cnumber_2 := complex(4, 6)
cvalue_1 := cmplx.Log10(cnumber_1)
cvalue_2 := cmplx.Log10(cnumber_2)
res := cvalue_1 + cvalue_2
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)
}
|
Output:
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...