Mathwords logoMathwords

Tanh — Definition, Formula & Examples

Tanh is the standard shorthand for the hyperbolic tangent function. It gives the ratio of sinh to cosh and maps every real number to an output between −1 and 1.

For any real number xx, the hyperbolic tangent is defined as tanh(x)=sinhxcoshx=exexex+ex\tanh(x) = \dfrac{\sinh x}{\cosh x} = \dfrac{e^{x} - e^{-x}}{e^{x} + e^{-x}}. The function is odd, continuous, and strictly increasing on (,)(-\infty, \infty), with horizontal asymptotes at y=1y = -1 and y=1y = 1.

Key Formula

tanh(x)=exexex+ex\tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
Where:
  • xx = Any real number (the input to the function)
  • ee = Euler's number, approximately 2.71828

How It Works

To evaluate tanh(x)\tanh(x), compute exe^{x} and exe^{-x}, then form the ratio (exex)/(ex+ex)(e^{x} - e^{-x})/(e^{x} + e^{-x}). For large positive xx, the exe^{-x} terms vanish and tanh(x)\tanh(x) approaches 1; for large negative xx, it approaches −1. At x=0x = 0, both numerator terms cancel and tanh(0)=0\tanh(0) = 0. This S-shaped, bounded behavior is why tanh appears frequently as an activation function in neural networks and as a solution profile in physics problems involving kink solitons.

Worked Example

Problem: Evaluate tanh(1) to four decimal places.
Compute the exponentials: Find e1e^{1} and e1e^{-1}.
e12.7183,e10.3679e^{1} \approx 2.7183, \quad e^{-1} \approx 0.3679
Form the ratio: Substitute into the tanh formula.
tanh(1)=2.71830.36792.7183+0.3679=2.35043.0862\tanh(1) = \frac{2.7183 - 0.3679}{2.7183 + 0.3679} = \frac{2.3504}{3.0862}
Divide: Perform the division to get the final value.
tanh(1)0.7616\tanh(1) \approx 0.7616
Answer: tanh(1)0.7616\tanh(1) \approx 0.7616

Why It Matters

In machine learning, tanh serves as an activation function that centers outputs around zero, often improving gradient flow compared to the logistic sigmoid. In physics and differential equations, tanh profiles describe shock-wave structures and domain walls, making it essential in applied mathematics courses.

Common Mistakes

Mistake: Confusing tanh with tan. Students sometimes apply trigonometric tangent identities to the hyperbolic tangent.
Correction: Remember that tanh(x)=(exex)/(ex+ex)\tanh(x) = (e^{x} - e^{-x})/(e^{x} + e^{-x}), which uses exponentials, not sine and cosine. The two functions have different domains, ranges, and periodicity (tanh is not periodic).

Related Terms