Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

r
math
tangent
communitycreator

What is tanh() in R?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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))

RELATED TAGS

r
math
tangent
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring