The math.cosh(x) function computes the hyperbolic cosine of a real numeric value x. Defined by the exponential formula cosh(x) = (ex + e−x) / 2, the function accepts any real number across (−∞, +∞) and returns a floating-point number strictly greater than or equal to 1.0.
Exact Inverse: Reverses the inverse hyperbolic cosine math.acosh() (math.cosh(math.acosh(y)) == y for all y ≥ 1.0). Unlike circular trigonometry, the parameter x is a dimensionless real number, not an angle in degrees or radians.
The math.cosh() function is part of Python's standard math module:
import math
result = math.cosh(x)
| Parameter | Type | Description |
|---|---|---|
x |
float or int |
Required. A real number representing the hyperbolic parameter. |
| Return Value | float |
The hyperbolic cosine of x, guaranteed to be ≥ 1.0. |
OverflowError |
Exception | Raised when |x| is large enough that cosh(x) exceeds ~1.79 × 10308 (typically |x| > 710.475). |
TypeError |
Exception | Raised when passing non-numeric types (e.g. strings or lists). |
At x = 0.0, cosh(0.0) reaches its global minimum of exactly 1.0. Because cosh(x) is an even function, it possesses perfect symmetry about the vertical axis: cosh(-x) == cosh(x):
import math
# Minimum value at zero
print("cosh(0.0): ", math.cosh(0.0)) # Output: 1.0
# Positive and negative inputs yield identical results (Even Symmetry)
print("cosh(1.0): ", round(math.cosh(1.0), 6)) # Output: 1.543081
print("cosh(-1.0):", round(math.cosh(-1.0), 6)) # Output: 1.543081
print("cosh(2.0): ", round(math.cosh(2.0), 6)) # Output: 3.762196
print("cosh(-2.0):", round(math.cosh(-2.0), 6)) # Output: 3.762196
Output:
cosh(0.0): 1.0
cosh(1.0): 1.543081
cosh(-1.0): 1.543081
cosh(2.0): 3.762196
cosh(-2.0): 3.762196
We can verify the mathematical formula (math.exp(x) + math.exp(-x)) / 2 using math.exp():
def formula_cosh(x):
return (math.exp(x) + math.exp(-x)) / 2.0
val = 3.5
print("math.cosh(3.5): ", math.cosh(val))
print("formula_cosh(3.5):", formula_cosh(val))
print("Matches? ", math.isclose(math.cosh(val), formula_cosh(val)))
Output:
math.cosh(3.5): 16.572824555025424
formula_cosh(3.5): 16.572824555025424
Matches? True
Just as circular sine and cosine satisfy the Pythagorean identity cos²(θ) + sin²(θ) = 1 on the unit circle, hyperbolic functions satisfy the fundamental hyperbolic identity on the unit hyperbola:
import math
test_points = [0.0, 0.5, 1.8, 5.0, -3.2]
for x in test_points:
c = math.cosh(x)
s = math.sinh(x)
diff = c**2 - s**2
print(f"x = {x:4.1f} | cosh^2 - sinh^2 = {diff:.12f} | Match: {math.isclose(diff, 1.0)}")
Output:
x = 0.0 | cosh^2 - sinh^2 = 1.000000000000 | Match: True
x = 0.5 | cosh^2 - sinh^2 = 1.000000000000 | Match: True
x = 1.8 | cosh^2 - sinh^2 = 1.000000000000 | Match: True
x = 5.0 | cosh^2 - sinh^2 = 1.000000000000 | Match: True
x = -3.2 | cosh^2 - sinh^2 = 1.000000000000 | Match: True
Learners often confuse math.cosh() with circular math.cos(). Their mathematical characteristics are completely distinct:
| Property | Circular math.cos(x) |
Hyperbolic math.cosh(x) |
|---|---|---|
| Geometry | Unit Circle: x2 + y2 = 1 |
Unit Hyperbola: x2 − y2 = 1 |
| Domain | (−∞, +∞) |
(−∞, +∞) |
| Range | Bounded: [−1.0, 1.0] |
Unbounded: [1.0, +∞) |
| Periodicity | Periodic: Repeats every 2π radians | Non-periodic: Monotonically grows as |x| → ∞ |
| Input Units | Angle in radians | Dimensionless real parameter |
| Physical Model | Harmonic oscillations, waves, rotations | Hanging chains, suspension cables (catenary) |
As |x| increases, cosh(x) grows exponentially (approximating ex / 2). When x exceeds approximately 710.4758, the computed float exceeds the maximum 64-bit IEEE 754 float capacity (~1.7977 × 10308), raising an OverflowError:
import math
print("cosh(100): ", math.cosh(100)) # 1.344058e+43
print("cosh(710): ", math.cosh(710)) # 1.116937e+308
try:
math.cosh(711)
except OverflowError as err:
print("cosh(711) OverflowError:", err)
Output:
cosh(100): 1.3440585709080678e+43
cosh(710): 1.1169371077717462e+308
cosh(711) OverflowError: math range error
We can graph the iconic U-shaped catenary curve using Matplotlib:
import math
import matplotlib.pyplot as plt
x_vals = [i * 0.1 - 5.0 for i in range(0, 101)] # -5.0 to +5.0
y_vals = [math.cosh(x) for x in x_vals]
plt.plot(x_vals, y_vals, label="y = cosh(x)", color="#1a73e8", linewidth=2)
plt.title("Hyperbolic Cosine: Catenary Profile")
plt.xlabel("x")
plt.ylabel("cosh(x)")
plt.grid(True, linestyle=":", alpha=0.6)
plt.legend()
plt.show()
In civil and electrical transmission engineering, high-voltage power cables suspended between two utility towers form a catenary curve under their own uniform gravitational weight:
Where a is the catenary scaling parameter (the ratio of horizontal tension to cable weight per unit length). For towers separated by span distance L, the maximum sag S at mid-span relative to the tower support height is given by:
import math
def calculate_catenary_sag(span_meters, catenary_param_a):
"""
Calculates cable sag at mid-span:
Sag = a * (cosh(span / (2 * a)) - 1)
"""
if span_meters < 0 or catenary_param_a <= 0:
raise ValueError("Span must be non-negative and parameter 'a' must be positive.")
half_span = span_meters / 2.0
sag = catenary_param_a * (math.cosh(half_span / catenary_param_a) - 1.0)
return round(sag, 4)
# Unit Assertions
# 0 meter span has 0 sag
assert calculate_catenary_sag(0.0, 500.0) == 0.0
# 200m span with parameter a = 1000m: 1000 * (cosh(100/1000) - 1) = 5.0042m
assert calculate_catenary_sag(200.0, 1000.0) == 5.0042
# 400m span with parameter a = 800m: 800 * (cosh(200/800) - 1) = 25.1307m
assert calculate_catenary_sag(400.0, 800.0) == 25.1307
# Validation error check
try:
calculate_catenary_sag(100.0, -50.0)
assert False, "Should raise ValueError"
except ValueError:
pass
print("Sag for 300m span (a = 1200m):", calculate_catenary_sag(300.0, 1200.0), "meters")
print("All catenary sag assertions passed successfully!")
Open in Google Colab View on GitHub
Run all math.cosh() examples interactively, verify exponential equivalence, test the fundamental identity cosh² − sinh² = 1, and compute power line catenary sag in Google Colab.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.