# Finding the Hyperbolic Cosine of Complex Number in Golang

In mathematics, hyperbolic functions are a class of functions that are analogs of the standard trigonometric functions. The hyperbolic cosine function (cosh z) is defined for complex numbers z as (e^z + e^-z)/2. In this article, we will discuss how to find the hyperbolic cosine of complex numbers in Golang.

## Syntax

The syntax for finding the hyperbolic cosine of a complex number in Golang is as follows −

## Example 1

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(3, 4)
fmt.Println("cosh(", z, ") = ", cmplx.Cosh(z))
}


## Output

cosh( (3+4i) ) =  (-6.580663040551157-7.581552742746545i)

In the above program, we first import the necessary packages fmt and math/cmplx. Then we define a complex number z with real part 3 and imaginary part 4. Finally, we use the cmplx.Cosh() function to find the hyperbolic cosine of the complex number z. The output of the program is the hyperbolic cosine of the complex number z.

## Example 2

Let's take another example of finding the hyperbolic cosine of a complex number in Golang.

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(1, 2)
fmt.Println("cosh(", z, ") = ", cmplx.Cosh(z))
}


## Output

cosh( (1+2i) ) =  (-0.64214812471552+1.068607421382778i)

In the above program, we first define a complex number z with real part 1 and imaginary part 2. Then we use the cmplx.Cosh() function to find the hyperbolic cosine of the complex number z. The output of the program is the hyperbolic cosine of the complex number z.

## Example 3

Let's take one more example of finding the hyperbolic cosine of a complex number in Golang.

package main

import (
"fmt"
"math/cmplx"
)

func main() {
z := complex(-3, 4)
fmt.Println("cosh(", z, ") = ", cmplx.Cosh(z))
}


## Output

cosh( (-3+4i) ) =  (-27.034945603074224-3.8511533348117775i)

In the above program, we first define a complex number z with real part -3 and imaginary part 4. Then we use the cmplx.Cosh() function to find the hyperbolic cosine of the complex number z. The output of the program is the hyperbolic cosine of the complex number z.

## Conclusion

In this article, we have discussed how to find the hyperbolic cosine of complex numbers in Golang. We have explained the syntax of the cmplx.Cosh() function and provided examples to help you understand how it works. You can now use this function to find the hyperbolic cosine of any complex number in Golang.

Updated on: 12-Apr-2023

170 Views