tanh

Hyperbolic tangent.

Category: Mathematics > Elementary Math

Syntax

Y = tanh(X)

Returns sinh(X)./cosh(X) for each element of X.

Description

tanh is an S-shaped curve: odd, increasing, close to x near zero and saturating at -1 and 1 for large arguments. It is a classic activation function in neural networks, and it also gives the magnetization of a spin in a mean-field model.

The identity tanh(x) = 2./(1 + exp(-2*x)) - 1 shows the relation to the logistic function.

Input arguments

X
Numeric array, real or complex.

Output arguments

Y
Array of the same size as X. For real input the values lie strictly between -1 and 1 (they reach the limits only through rounding).

Example

Saturation

tanh([0 0.5 1 3 20])
tanh(-100)
Output
ans = 1×5

         0    0.4621    0.7616    0.9951    1.0000
ans = -1

See also

sinh cosh atanh tan exp