Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python math.cosh() Method



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

The hyperbolic cosine method, denoted ascosh(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 Pythonmath.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 mathx = 2.0result = 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 mathfrom fractions import Fractionx = 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 mathx = -0.5result = math.cosh(x)print(result)

Output

We get the output as shown below −

1.1276259652063807

Example 4

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

import mathvalues = [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.5430806348152437cosh(2.0) = 3.7621956910836314cosh(3.0) = 10.067661995777765
python_maths.htm
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp