R Tutorial R Charts & Graphs R Statistics R References

R - cosh() Function



The R cosh() function returns hyperbolic cosine of a value. The hyperbolic cosine of x is defined as:

cosh

where e is an Euler's number.

In special cases it returns the following:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is positive infinity.
  • If the argument is zero, then the result is 1.0.

Syntax

cosh(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns the hyperbolic cosine of the value.

Example:

In the example below, cosh() function is used to find out the hyperbolic cosine of the value.

#operating on single element atomic vector
print(cosh(-5))
print(cosh(0))
print(cosh(5))

cat("\nOperating on vector\n")
#operating on vector
v <- c(0, 3, 5)
print(cosh(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(-5, -2, 0, 2, 5, NaN), nrow=2)
print(cosh(m))

cat("\nOperating on first column of matrix\n")
#operating on first column of matrix
print(cosh(m[,1]))

The output of the above code will be:

[1] 74.20995
[1] 1
[1] 74.20995

Operating on vector
[1]  1.00000 10.06766 74.20995

Operating on matrix
          [,1]     [,2]     [,3]
[1,] 74.209949 1.000000 74.20995
[2,]  3.762196 3.762196      NaN

Operating on first column of matrix
[1] 74.209949  3.762196

❮ R Math Functions