The atanh() function in R is used to calculate the inverse hyperbolic tangent of a number.
The inverse hyperbolic tangent function is the inverse of the hyperbolic tangent function, tanh().
Syntax
atanh(x)
Parameters
x: A numeric value, array, vector, or matrix.
- If you pass the NaN argument, it returns NaN.
- If you pass the absolute value greater than 1, it returns NaN.
- If the argument is 1 or -1, the output is infinity with the same sign as the argument.
Example 1: Basic usage
atanh(1)
atanh(0)
Output
[1] Inf
[1] 0
Example 2: Passing complex number
com <- 5 + 1i
atanh(com)
Output
[1] 0.194426+1.530881i
Example 3: Using vector
vec <- c(-1, 0.5, 0, 0.5, 1)
atanh(vec)
Output
[1] -Inf 0.5493061 0.0000000 0.5493061 Inf
Example 4: Using a matrix
mtrx <- matrix(c(-0.8, -0.1, 0, 0.1, 0.8, NaN), nrow = 2)
print(atanh(mtrx))
Output
[,1] [,2] [,3]
[1,] -1.0986123 0.0000000 1.098612
[2,] -0.1003353 0.1003353 NaN
Example 5: Using pi
atanh(pi)
atanh(pi / 4)
Output
[1] NaN
Warning message:
In atanh(pi) : NaNs produced
[1] 1.059306
Example 6: Plotting
dt <- seq(-1, 1, by = 0.05)
plot(dt, atanh(dt), typ = "l", col = "red")
abline(v = 0, lty = 6, col = "blue")
Output
That’s it!
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.