Ref Math Cosh
## Python math.cosh() Method
The `math.cosh()` method is a built-in function in Python's standard `math` module. It returns the hyperbolic cosine of a given number $x$.
Mathematically, the hyperbolic cosine of $x$ is defined as:
$$\cosh(x) = \frac{e^x + e^{-x}}{2}$$
Where $e$ is Euler's number (approximately 2.71828).
---
### Syntax
To use the `math.cosh()` method, you must first import the `math` module:
```python
import math
math.cosh(x)
```
### Parameters
| Parameter | Type | Description |
| :--- | :--- | :--- |
| `x` | `float` or `int` | **Required.** A real number (positive, negative, or zero). |
### Return Value
* **Type:** `float`
* **Description:** Returns a floating-point value representing the hyperbolic cosine of the input number `x`.
### Exceptions
* If `x` is not a numeric value (e.g., a string or a list), the method raises a **`TypeError`**.
* If the value of `x` is too large, the calculation will overflow and raise an **`OverflowError`**.
---
### Code Examples
The following example demonstrates how to calculate the hyperbolic cosine for various types of numbers (positive, negative, zero, and floating-point numbers):
```python
# Import the math module
import math
# Calculate hyperbolic cosine for different values
print("cosh(1): ", math.cosh(1))
print("cosh(8.90):", math.cosh(8.90))
print("cosh(0): ", math.cosh(0))
print("cosh(1.52):", math.cosh(1.52))
print("cosh(-1.52):", math.cosh(-1.52)) # cosh(x) is an even function, so cosh(-x) == cosh(x)
```
#### Output:
```text
cosh(1): 1.5430806348152437
cosh(8.90): 3665.986837772461
cosh(0): 1.0
cosh(1.52): 2.395468541047187
cosh(-1.52): 2.395468541047187
```
---
### Technical Considerations
1. **Symmetry (Even Function):**
The hyperbolic cosine function is symmetric about the y-axis, meaning $\cosh(-x) = \cosh(x)$. As shown in the example above, passing `1.52` and `-1.52` yields the exact same result.
2. **Minimum Value:**
The minimum value of $\cosh(x)$ is always `1.0`, which occurs when $x = 0$. For any other real number $x$, $\cosh(x) > 1.0$.
3. **Handling Large Inputs (Overflow):**
Because $\cosh(x)$ grows exponentially, passing a very large number will result in an `OverflowError`. For example:
```python
import math
try:
print(math.cosh(1000))
except OverflowError as e:
print("Error:", e) # Output: Error: math range error
```
YouTip