Python math.cosh() Method



The Python math.cosh() method returns the hyperbolic cosine of a given number.

The hyperbolic cosine method, denoted as cosh(x), is a mathematical method that calculates the value of the cosine of a complex number or a real number x. It returns real values greater than or equal to 1.

Mathematically, the hyperbolic cosine method is defined as −

cosh(x) = (ex + e-x)/ 2

Where, e is the base of the natural logarithm, approximately equal to 2.71828. This method is symmetric with respect to the y-axis, meaning that cosh(x) = cosh(-X).

Syntax

Following is the basic syntax of the Python math.cosh() method −

math.cosh(x)

Parameters

This method accepts a number (all real number) for which you want to find the hyperbolic cosine as a parameter.

Return Value

The method returns the hyperbolic cosine of the given number in the range of [1, ∞).

Example 1

In the following example, we calculate the hyperbolic cosine of a positive number using the math.cosh() method −

import math
x = 2.0
result = math.cosh(x)
print(result) 

Output

The output obtained is as follows −

3.7621956910836314

Example 2

If we pass a fraction value to the math.cosh() method, it returns a positive real number −

import math
from fractions import Fraction
x = Fraction(5, -9)
result = math.cosh(x)
print(result) 

Output

Following is the output of the above code −

1.1583312096854452

Example 3

In here, we are retrieving the hyperbolic cosine of a negative number using the math.cosh() method −

import math
x = -0.5
result = math.cosh(x)
print(result)  

Output

We get the output as shown below −

1.1276259652063807

Example 4

In this example, we use a loop to calculate the hyperbolic cosine of multiple values using the math.cosh() method. The loop iterates through each value in the values list, calculates the hyperbolic cosine, and prints the result for each value −

import math
values = [1.0, 2.0, 3.0]
for x in values:
   result = math.cosh(x)
   print("cosh({}) = {}".format(x, result))

Output

The result produced is as shown below −

cosh(1.0) = 1.5430806348152437
cosh(2.0) = 3.7621956910836314
cosh(3.0) = 10.067661995777765
python_maths.htm
Advertisements