tanh
tanh(x)
Compute hyperbolic tangent of x
Examples
-
Compute hyperbolic tangent of a number:
julia> tanh(0.5) 0.4621171572600098This example calculates the hyperbolic tangent of the number 0.5.
-
Calculate hyperbolic tangent of an array:
julia> arr = [1.0, 2.0, 3.0]; julia> tanh.(arr) 3-element Array{Float64,1}: 0.7615941559557649 0.9640275800758169 0.9950547536867305The
tanh.notation applies thetanhfunction element-wise to the arrayarr. - 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.999329Using 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.