Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
communitycreator

How to use inverse hyperbolic functions in Ruby

harris910

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:

asinh(x)=ln(x+(x2+1))asinh(x) =ln(x+√(x^{2}+1))

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:

acosh(x)=ln(x+(x21))acosh(x) =ln(x+√(x^{2}-1))

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:

atanh(x)=12ln(1+x1x)atanh(x)=\frac {1}{2}ln(\frac {1+x}{1-x})

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 radians
print "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 radians
print "The value of asinh(-0.5) : ",  Math.asinh(-0.5), "\n"
print "The value of atanh(-0.5) : ",  Math.atanh(-0.5), "\n"

#zero
print "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.

RELATED TAGS

ruby
communitycreator
RELATED COURSES

View all Courses

Keep Exploring