Python math.atanh() Method



The Python math.atanh() method returns the inverse hyperbolic tangent of a given number.

The inverse hyperbolic tangent method, denoted as tanh-1(x) or sometimes as artanh(x), is a mathematical method that retrieves the value whose hyperbolic tangent is a given number x. In other words, if you have a value x between -1 and 1, the inverse hyperbolic tangent method will return the number whose hyperbolic tangent equals x.

Mathematically, this is expressed as −

tanh-1(x) = value y such that tanh(y) = x

The domain of the inverse hyperbolic tangent method is restricted to the interval (-1, 1) since the range of the hyperbolic tangent method range is also (-1, 1). The output of the inverse hyperbolic tangent method will always be a real number.

Syntax

Following is the basic syntax of the Python math.atanh() method −

math.atanh(x)

Parameters

This method accepts a number in the domain of (-1 to 1) for which you want to find the inverse hyperbolic tangent as a parameter.

Return Value

The method returns the inverse hyperbolic tangent of the given number in the range of (-∞, ∞).

Example 1

The hyperbolic tangent of 0 is 0. Therefore, when we pass 0 as an argument to math.atanh() method, it returns 0.0 −

import math
x = 0
result = math.atanh(x)
print(result) 

Output

The output obtained is as follows −

0.0

Example 2

If we pass a fraction value to the math.atanh() method, it returns a real number −

import math
from fractions import Fraction
x = Fraction(5, -9)
result = math.atanh(x)
print(result) 

Output

Following is the output of the above code −

-0.626381484247684

Example 3

In here, we are retrieving the inverse hyperbolic tangent of a negative number using the math.atanh() method −

import math
x = -0.5
result = math.atanh(x)
print(result)  

Output

We get the output as shown below −

-0.5493061443340548

Example 4

When we pass a larger number to the math.atanh() method, it results in a domain error because the inverse hyperbolic tangent method is defined only for numbers -1 to 1 (exclusive) −

import math
x = 1000
result = math.atanh(x)
print(result) 

Output

The result produced is as shown below −

Traceback (most recent call last):
  File "/home/cg/root/65fbd333dfa67/main.py", line 3, in <module>
result = math.atanh(x)
ValueError: math domain error
python_maths.htm
Advertisements