# Finding the Inverse Cosine of Complex Number in Golang

The inverse cosine of a complex number is the angle whose cosine is that complex number. In Golang, we can use the cmath.Acos function to find the inverse cosine of a complex number. In this article, we will learn how to find the inverse cosine of a complex number in Golang with examples.

## Syntax

func Acos(z complex128) complex128


The cmath.Acos function takes a complex number as input and returns its inverse cosine value as a complex number.

## Example 1

Let's find the inverse cosine of the complex number (1+0i).

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(1, 0)
acos := cmplx.Acos(z)
fmt.Printf("acos(%v) = %v\n", z, acos)
}


## Output

acos((1+0i)) = (0-0i)


In this example, we created a complex number z using the complex function, which takes two floating-point values as input and returns a complex number. We then used the cmath.Acos function to find the inverse cosine of z and stored the result in the acos variable. Finally, we printed the value of acos using the fmt.Printf function.

## Example 2

Let's find the inverse cosine of the complex number (0.5+0.5i).

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(0.5, 0.5)
acos := cmplx.Acos(z)
fmt.Printf("acos(%v) = %v\n", z, acos)
}


## Output

acos((0.5+0.5i)) = (1.1185178796437059-0.5306375309525178i)


In this example, we created a complex number z using the complex function and then used the cmath.Acos function to find its inverse cosine value.

## Example 3

Let's find the inverse cosine of the complex number (-1+0i).

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(-1, 0)
acos := cmplx.Acos(z)
fmt.Printf("acos(%v) = %v\n", z, acos)
}


## Output

acos((-1+0i)) = (3.141592653589793-0i)


In this example, we created a complex number z using the complex function and then used the cmath.Acos function to find its inverse cosine value.

## Conclusion

In this article, we learned how to find the inverse cosine of a complex number in Golang using the cmath.Acos function. The cmath.Acos function takes a complex number as input and returns its inverse cosine value as a complex number. We also saw some examples of finding the inverse cosine of different complex numbers using Golang.

Updated on: 12-Apr-2023

58 Views