How to use inverse hyperbolic functions in Ruby
The asinh() function
The asinh() function returns the inverse hyperbolic sine of a number.
The figure below shows the mathematical representation of the asinh() function:
The acosh() function
The acosh() function returns the inverse hyperbolic cosine of a number.
The figure below shows the mathematical representation of the acosh() function:
The atanh() function
The atanh() function returns the inverse hyperbolic tangent of a number.
The figure below shows the mathematical representation of the atanh() function:
Syntax
asinh(angle)
acosh(angle)
atanh(angle)
Parameters
These functions require an angle in radians as a parameter.
- The angle sent to
acosh()should be greater than 1 otherwise it returns domain error. - The angle sent to
atanh()should be between 1 and -1 otherwise it returns domain error.
Return value
-
The
asinh()function returns the inverse hyperbolic sine of the angle sent as a parameter. -
The
acosh()function returns the inverse hyperbolic cosine of the angle sent as a parameter. -
The
atanh()function returns the inverse hyperbolic tangent of the angle sent as a parameter.
Example
The code below demonstrates how to use the inverse hyperbolic functions function in Ruby:
#positive number in radiansprint "The value of asinh(0.5) : ", Math.asinh(0.5), "\n"print "The value of acosh(1.5) : ", Math.acosh(1.5), "\n"print "The value of atanh(0.5) : ", Math.atanh(0.5), "\n"#negative number in radiansprint "The value of asinh(-0.5) : ", Math.asinh(-0.5), "\n"print "The value of atanh(-0.5) : ", Math.atanh(-0.5), "\n"#zeroprint "The value of asinh(0) : ", Math.asinh(0), "\n"print "The value of atanh(0) : ", Math.atanh(0), "\n"
Explanation
- Lines 2–4 : We calculate the inverse hyperbolic function of the positive number in radians.
- Lines 7–8 : We calculate the inverse hyperbolic function of the negative number in radians.
- Lines 11–12 : We calculate the inverse hyperbolic function of the zero in radians.