Compute hyperbolic tangent of x


  1. Compute hyperbolic tangent of a number:

    julia> tanh(0.5)

    This example calculates the hyperbolic tangent of the number 0.5.

  2. Calculate hyperbolic tangent of an array:

    julia> arr = [1.0, 2.0, 3.0];
    julia> tanh.(arr)
    3-element Array{Float64,1}:

    The tanh. notation applies the tanh function element-wise to the array arr.

  3. Compute hyperbolic tangent of a matrix:
    julia> matrix = [1.0 2.0; 3.0 4.0];
    julia> tanh.(matrix)
    2×2 Array{Float64,2}:
    0.761594  0.964028
    0.995055  0.999329

    Using the tanh. notation, we can calculate the hyperbolic tangent of each element in the matrix.

Common mistake example:

julia> tanh("[1, 2, 3]")
ERROR: MethodError: no method matching tanh(::String)

In this example, the tanh function is called with a string as an argument. The tanh function operates on numeric types, so passing a string will result in a MethodError. Make sure to provide valid numeric inputs to the tanh function.

See Also

acos, acosd, acosh, acot, acotd, acoth, acsc, acscd, acsch, asec, asecd, asech, asin, asind, asinh, atan, atan2, atand, atanh, cos, cosc, cosd, cosh, cospi, cot, cotd, coth, csc, cscd, csch, deg2rad, rad2deg, sin, sinc, sind, sinh, sinpi, tan, tand, tanh,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: