{"id":24401,"date":"2021-10-14T09:19:16","date_gmt":"2021-10-14T03:49:16","guid":{"rendered":"https:\/\/python-programs.com\/?p=24401"},"modified":"2021-11-05T21:07:19","modified_gmt":"2021-11-05T15:37:19","slug":"python-program-for-cosh-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-cosh-function\/","title":{"rendered":"Python Program for cosh() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for isalpha() Function<\/a> The math.cosh() method calculates a number’s hyperbolic cosine (equivalent to (exp(number) + exp(-number)) \/ 2).<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n x:<\/strong> 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.<\/p>\n Return Value:<\/strong><\/p>\n Returns a float value representing a number’s hyperbolic cosine.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples<\/a> well explained step by step.<\/p>\n 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 …<\/p>\n
\ncosh() Function in Python:<\/strong><\/p>\nmath.cosh(x)<\/pre>\n
\n
Given first number = 0.4\r\nGiven second number = 1<\/pre>\n
The result after applying cosh() function on above given first number 0.4 = 1.081072371838455\r\nThe result after applying cosh() function on above given second number 1 = 1.5430806348152437<\/pre>\n
Given first number = 6.5\r\nGiven second number = 2<\/pre>\n
The result after applying cosh() function on above given first number 6.5 = 332.5715682417774\r\nThe result after applying cosh() function on above given second number 2 = 3.7621956910836314<\/pre>\n
Program for cosh() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [0.5, 0.2, 1, 0.8]\r\n# Give the first number as static input and store it in another variable.\r\ngvn_numb1 = 0.4\r\n# Apply math.cosh() function to the given first number to get the hyperbolic\r\n# cosine value of a given number.\r\n# Store it in another variable.\r\nfnl_rslt = math.cosh(gvn_numb1)\r\n# Print the above result\r\nprint(\"The result after applying cosh() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = 1\r\nprint(\"The result after applying cosh() function on above given second number\",\r\n gvn_numb2, \" = \", math.cosh(gvn_numb2))\r\n# Apply math.cosh() function to the given list element and print it.\r\nprint(\r\n \"The result after applying cosh() function on given list element gvnlst[1] = \", math.cosh(gvn_lst[1]))\r\n<\/pre>\n
The result after applying cosh() function on above given first number 0.4 = 1.081072371838455\r\nThe result after applying cosh() function on above given second number 1 = 1.5430806348152437\r\nThe result after applying cosh() function on given list element gvnlst[1] = 1.020066755619076<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(float, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the first number as user input using the float(input()) function\r\n# and store it in a variable.\r\ngvn_numb1 = float(input(\"Enter some random number = \"))\r\n# Apply math.cosh() function to the given first number to get the hyperbolic\r\n# cosine value of a given number.\r\n# Store it in another variable.\r\nfnl_rslt = math.cosh(gvn_numb1)\r\n# Print the above result.\r\nprint(\"The result after applying cosh() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = float(input(\"Enter some random number = \"))\r\nprint(\"The result after applying cosh() function on above given second number\",\r\n gvn_numb2, \" = \", math.cosh(gvn_numb2))\r\n# Apply math.cosh() function to the given list element and print it.\r\nprint(\r\n \"The result after applying cosh() function on given list element gvnlst[2] = \", math.cosh(gvn_lst[2]))\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 2 3 4 1 5\r\nEnter some random number = 6.5\r\nThe result after applying cosh() function on above given first number 6.5 = 332.5715682417774\r\nEnter some random number = 2\r\nThe result after applying cosh() function on above given second number 2.0 = 3.7621956910836314\r\nThe result after applying cosh() function on given list element gvnlst[2] = 27.308232836016487<\/pre>\n
\n