R atanh() Function

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.

  1. If you pass the NaN argument, it returns NaN.
  2. If you pass the absolute value greater than 1, it returns NaN.
  3. If the argument is 1 or -1, the output is infinity with the same sign as the argument.

Example 1: Basic usage

Usage of atanh() function

atanh(1)

atanh(0)

Output

[1] Inf

[1] 0

Example 2: Passing complex number

Calculating atanh() of a complex number

com <- 5 + 1i

atanh(com)

Output

[1] 0.194426+1.530881i

Example 3: Using vector

Calculating atanh() of a 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

Plotting of atanh() in R

That’s it!

Leave a Comment