Home »
Python
math.cosh() method with example in Python
Python math.cosh() method: Here, we are going to learn about the math.cosh() method with example in Python.
Submitted by IncludeHelp, on April 25, 2019
Python math.cosh() method
math.cosh() method is a library method of math module, it is used to get the hyperbolic cosine of given number in radians, it accepts a number and returns hyperbolic cosine.
Note: math.cosh() method accepts only numbers, if we provide anything else except the number, it returns error TypeError – "TypeError: a float is required".
Syntax of math.cosh() method:
math.cosh(x)
Parameter(s): x – is the number whose hyperbolic cosine to be calculated.
Return value: float – it returns a float value that is the hyperbolic cosine value of the number x.
Example:
Input:
x = 1.5
# function call
print(math.cosh(x))
Output:
2.352409615243247
Python code to demonstrate example of math.cosh() method
# Python code to demonstrate example of
# math.cosh() method
# importing math module
import math
# number
x = -10
print("math.cosh(",x,"): ", math.cosh(x))
x = 0
print("math.cosh(",x,"): ", math.cosh(x))
x = 1.5
print("math.cosh(",x,"): ", math.cosh(x))
x = 5
print("math.cosh(",x,"): ", math.cosh(x))
x = 15.45
print("math.cosh(",x,"): ", math.cosh(x))
Output
math.cosh( -10 ): 11013.232920103324
math.cosh( 0 ): 1.0
math.cosh( 1.5 ): 2.352409615243247
math.cosh( 5 ): 74.20994852478785
math.cosh( 15.45 ): 2563419.889913628
TypeError example
# Python code to demonstrate example of
# math.cosh() method with exception
# importing math module
import math
# number
x = "2.5"
print("math.cosh(",x,"): ", math.cosh(x))
Output
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("math.cosh(",x,"): ", math.cosh(x))
TypeError: a float is required