In the previous article, we have discussed Python Program for isalpha() Function
cosh() Function in Python:
The math.cosh() method calculates a number’s hyperbolic cosine (equivalent to (exp(number) + exp(-number)) / 2).
Syntax:
math.cosh(x)
Parameters:
x: This is Required. It is a number for which the hyperbolic cosine must be calculated. If the value is not a number, a TypeError is returned.
Return Value:
Returns a float value representing a number’s hyperbolic cosine.
- The cosh function returns the Hyperbolic Cosine value if the number argument is positive or negative.
- The cosh function returns TypeError if the number argument is not a number.
Examples:
Example1:
Input:
Given first number = 0.4 Given second number = 1
Output:
The result after applying cosh() function on above given first number 0.4 = 1.081072371838455 The result after applying cosh() function on above given second number 1 = 1.5430806348152437
Example2:
Input:
Given first number = 6.5 Given second number = 2
Output:
The result after applying cosh() function on above given first number 6.5 = 332.5715682417774 The result after applying cosh() function on above given second number 2 = 3.7621956910836314
Program for cosh() Function in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Import math module using the import keyword.
- Give the list as static input and store it in a variable.
- Give the first number as static input and store it in another variable.
- Apply math.cosh() function to the given first number to get the hyperbolic cosine value of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.cosh() function to the given list element and print it.
- The Exit of Program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the list as static input and store it in a variable. gvn_lst = [0.5, 0.2, 1, 0.8] # Give the first number as static input and store it in another variable. gvn_numb1 = 0.4 # Apply math.cosh() function to the given first number to get the hyperbolic # cosine value of a given number. # Store it in another variable. fnl_rslt = math.cosh(gvn_numb1) # Print the above result print("The result after applying cosh() function on above given first number", gvn_numb1, " = ", fnl_rslt) # similarly do the same for the other number. gvn_numb2 = 1 print("The result after applying cosh() function on above given second number", gvn_numb2, " = ", math.cosh(gvn_numb2)) # Apply math.cosh() function to the given list element and print it. print( "The result after applying cosh() function on given list element gvnlst[1] = ", math.cosh(gvn_lst[1]))
Output:
The result after applying cosh() function on above given first number 0.4 = 1.081072371838455 The result after applying cosh() function on above given second number 1 = 1.5430806348152437 The result after applying cosh() function on given list element gvnlst[1] = 1.020066755619076
Method #2: Using Built-in Functions (User Input)
Approach:
- Import math module using the import keyword.
- Give the list as user input using list(),map(),input(),and split() functions.
- Store it in a variable.
- Give the first number as user input using the float(input()) function and store it in a variable.
- Apply math.cosh() function to the given first number to get the hyperbolic cosine value of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.cosh() function to the given list element and print it.
- The Exit of Program.
Below is the implementation:
# Import math module using the import keyword. import math # Give the list as user input using list(),map(),input(),and split() functions. # Store it in a variable. gvn_lst = list(map(float, input( 'Enter some random List Elements separated by spaces = ').split())) # Give the first number as user input using the float(input()) function # and store it in a variable. gvn_numb1 = float(input("Enter some random number = ")) # Apply math.cosh() function to the given first number to get the hyperbolic # cosine value of a given number. # Store it in another variable. fnl_rslt = math.cosh(gvn_numb1) # Print the above result. print("The result after applying cosh() function on above given first number", gvn_numb1, " = ", fnl_rslt) # similarly do the same for the other number. gvn_numb2 = float(input("Enter some random number = ")) print("The result after applying cosh() function on above given second number", gvn_numb2, " = ", math.cosh(gvn_numb2)) # Apply math.cosh() function to the given list element and print it. print( "The result after applying cosh() function on given list element gvnlst[2] = ", math.cosh(gvn_lst[2]))
Output:
Enter some random List Elements separated by spaces = 2 3 4 1 5 Enter some random number = 6.5 The result after applying cosh() function on above given first number 6.5 = 332.5715682417774 Enter some random number = 2 The result after applying cosh() function on above given second number 2.0 = 3.7621956910836314 The result after applying cosh() function on given list element gvnlst[2] = 27.308232836016487
Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.