Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

First Derivative tanh'(x)
0.786448
= 1 - tanh(x)^2
tanh(x) 0.462117
tanh'(x) 0.786448
tanh''(x) -0.726862

What this calculator does

This tool evaluates the hyperbolic tangent function \(\tanh(x)\) and, more importantly, its first derivative \(\tanh'(x)\) at any real input \(x\). It also reports the second derivative \(\tanh''(x)\). The hyperbolic tangent is a smooth, S-shaped (sigmoidal) function whose output is bounded between -1 and 1, which is why it appears so often as a neural-network activation function and in physics and engineering models.

How to use it

Enter any real number for \(x\) and submit. The calculator computes \(\tanh(x)\) once, then derives both the first and second derivatives from that single value. There are no units to convert: \(x\) is a dimensionless real number, and all outputs are dimensionless as well.

The formula explained

The hyperbolic tangent is $$\tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}.$$ Its first derivative has the elegant closed form $$f'(x) = 1 - \tanh^{2}(x),$$ equivalently \(\operatorname{sech}^2(x) = \frac{1}{\cosh^2(x)}\). Because \(\tanh(x)\) lies in \((-1, 1)\), the first derivative always lies in \((0, 1]\), peaking at \(x = 0\) where the slope is exactly 1. The second derivative is $$f''(x) = -2\tanh(x)\left(1 - \tanh^{2}(x)\right),$$ an odd function that crosses zero at \(x = 0\).

Advertisement
Graph of tanh(x) S-curve and its bell-shaped derivative
The tanh function (S-curve) and its first derivative 1 - tanh²(x), a bell-shaped hump peaking at x = 0.

Worked example (x = 0.5)

$$\tanh(0.5) = \frac{1.6487212707 - 0.6065306597}{1.6487212707 + 0.6065306597} = 0.4621171573.$$ Then $$f'(0.5) = 1 - 0.4621171573^{2} = 0.7864477541,$$ and $$f''(0.5) = -2 \times 0.4621171573 \times 0.7864477541 = -0.7269278407.$$

Tangent line touching the tanh curve at x = 0.5 showing the slope
At x = 0.5 the derivative equals the slope of the tangent line to the tanh curve.

FAQ

Why does the gradient vanish for large x? As \(x\) grows, tanh saturates toward \(\pm 1\), so \(1 - \tanh^2\) approaches 0. This "vanishing gradient" can slow training in deep networks.

Is the derivative ever negative? No. \(f'(x) = \operatorname{sech}^2(x)\) is strictly positive for all real \(x\), so tanh is always increasing.

Is there any divide-by-zero risk? No. \(\cosh(x)\) is at least 1 for every real \(x\), so \(\operatorname{sech}^2(x)\) is always well defined.

Last updated: