What is tanh() in R?

The tanh() function in R returns a number’s hyperbolic tangent in radians.

The following illustration shows the mathematical representation of the tanh() function.

Figure 1: Mathematical representation of the hyperbolic tangent function

Syntax

tanh(num)

Parameter

This function requires a number that represents an angle in radians as a parameter.

To convert degrees to radians, use:

radians = degrees * ( PI / 180.0 )

Return value

tanh() returns the hyperbolic tangent of a number (in radians) that is set as a parameter.

Code

#positive number in radians
a <- tanh(2.3);
print(paste0("tanh(2.3): ", a))
#negative number in radians
b <- tanh(-2.3);
print(paste0("tanh(-2.3): ", b))
#converting the degrees angle into radians and then applying tanh()
#degrees = 45
c <- tanh(45 * (pi / (180)));
print(paste0("tanh(45 * (pi / (180))): ", c))

Free Resources