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 , the hyperbolic tangent is defined as . The function is odd, continuous, and strictly increasing on , with horizontal asymptotes at and .
Key Formula
Where:
- = Any real number (the input to the function)
- = Euler's number, approximately 2.71828
How It Works
To evaluate , compute and , then form the ratio . For large positive , the terms vanish and approaches 1; for large negative , it approaches −1. At , both numerator terms cancel and . 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 and .
Form the ratio: Substitute into the tanh formula.
Divide: Perform the division to get the final value.
Answer:
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 , which uses exponentials, not sine and cosine. The two functions have different domains, ranges, and periodicity (tanh is not periodic).
