R cosh() Function

The cosh() function in R is used to calculate the hyperbolic cosine of a numeric input in radians.

Syntax

cosh(x)

Parameters

x: It is a column to calculate.

Return value

It returns the hyperbolic cosine of a number (in radians) sent in as a parameter.

Example 1: Basic usage

Usage of cosh() function

cosh(1)

cosh(0)

Output

[1] 1.543081

[1] 1

Example 2: Providing a complex number

Passing a complex number

com <- 5 + 1i

cosh(com)

Output

[1] 40.09581+62.43985i

Example 3: Using vector

Using the cosh() function with a Vector

vec <- c(-1, 0.5, 0, 0.5, 1)

cosh(vec)

Output

[1] 1.543081 1.127626 1.000000 1.127626 1.543081

Example 4: Passing a pi

Let’s find the pi constant’s cosh() value.

cosh(pi)

cosh(pi / 4)

Output

[1] 11.59195

[1] 1.324609

Example 5: Plotting

dt <- seq(-1, 1, by = 0.05)
plot(dt, cosh(dt), typ = "l", col = "red")
abline(v = 0, lty = 6, col = "blue")

Output

Plotting cosh() Function

That’s it.

Leave a Comment