The cosh() function in R is “used to calculate the hyperbolic cosine of a number in radians“. It accepts the numerical value as an argument and returns the hyper tangent of the cosine of that numeric value.
x: It is a column to calculate.
The cosh() function returns the hyperbolic cosine of a number (in radians) sent in as a parameter.
Example 1: R program to use the cosh() function
Let’s calculate the cosh value of 1.
Let’s calculate the cosh value of 0.
Example 2: Using the cosh() function with a complex number
Define a complex value and pass that value to the cosh() function.
d <- 5 + 1i cosh(d)
Example 3: Using the cosh() function with a Vector
To create a Vector in R, you can use the c() function. Then pass that vector to the cosh() function.
rv <- c(-1, 0.5, 0, 0.5, 1) cosh(rv)
 1.543081 1.127626 1.000000 1.127626 1.543081
Example 4: Passing a pi to the cosh() function
The pi is an inbuilt constant in R programming, and its value is 3.141593.
Let’s find the pi constant’s cosh() value.
Let’s see another example of pi.
cosh(pi / 4)
Plotting the cosh() function to a graph
We can use the seq() function to create a series of values and pass that to the plot() function, creating a line chart.
dt <- seq(-1, 1, by = 0.05) plot(dt, cosh(dt), typ = "l", col = "red") abline(v = 0, lty = 6, col = "blue")
Krunal Lathiya is a Software Engineer with over eight years of experience. He has developed a strong foundation in computer science principles and a passion for problem-solving. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language.