Finding the Hyperbolic Tangent of Complex Number in Golang


In mathematics, hyperbolic functions are a group of functions that are analogous to trigonometric functions. They are defined in terms of exponential functions and can be used to model various phenomena in science and engineering. In Go language, the math/cmplx package provides various hyperbolic functions to work with complex numbers.

In this article, we will discuss how to find the hyperbolic tangent of complex numbers in Go using the math/cmplx package. We will also provide some examples to help illustrate the concept.

Hyperbolic Tangent

The hyperbolic tangent function is defined as −

tanh(z) = (e^z - e^-z) / (e^z + e^-z)

where z is a complex number.

The hyperbolic tangent is an odd function, which means that tanh(-z) = -tanh(z). It is also periodic with period πi. The range of the hyperbolic tangent function is (-1, 1).

Finding Hyperbolic Tangent of Complex Number in Golang

In Go, the hyperbolic tangent of a complex number can be found using the cmplx.Tanh function. This function takes a complex number as its argument and returns its hyperbolic tangent. The function has the following signature −

func Tanh(z complex128) complex128

The Tanh function takes a complex number z of type complex128 and returns its hyperbolic tangent as a complex number of type complex128.

Here's an example of how to use the Tanh function −

Example

package main

import (
   "fmt"
   "math/cmplx"
)

func main() {
   z := complex(2, 3)
   tanh := cmplx.Tanh(z)
   fmt.Printf("tanh(%v) = %v\n", z, tanh)
}

Output

tanh((2+3i)) = (0.965385879022133-0.009884375038322494i)

In the above example, we created a complex number z with real part 2 and imaginary part 3. We then used the Tanh function to find its hyperbolic tangent, which was assigned to the tanh variable. Finally, we printed the value of the tanh variable using the fmt.Printf function.

Conclusion

In this article, we discussed how to find the hyperbolic tangent of complex numbers in Go using the math/cmplx package. We also provided an example to help illustrate the concept. Hyperbolic functions are important mathematical tools that are used in various fields of science and engineering, and being able to work with them in Go can be very useful.

Updated on: 12-Apr-2023

199 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements