Python math.atanh() Method

Python math.atanh() Method

  1. Syntax of Python math.atanh() Method
  2. Example Codes: Use math.atanh() Method in Python
  3. Example Codes: Code Demonstrates an Error of the math.atanh() Method
  4. Example Codes: Use the Equivalent of the math.atanh() Method

Python math.atanh() method is an efficient way of calculating the inverse hyperbolic tangent of a number, x, in radians.

Syntax of Python math.atanh() Method

math.atanh(x)

Parameters

x Any positive or negative value in the range -0.99 and 0.99.

Return

The return type of this method is a float value representing the arctangent of x.

Example Codes: Use math.atanh() Method in Python

import math

x=-0.9
value=math.atanh(x)
print(f"The inverse hyperbolic tangent of {x} is {value}.")

x=0
value=math.atanh(x)
print(f"The inverse hyperbolic tangent of {x} is {value}.")

x=0.0086
value=math.atanh(x)
print(f"The inverse hyperbolic tangent of {x} is {value}.")

Output:

The inverse hyperbolic tangent of -0.9 is -1.4722194895832204.
The inverse hyperbolic tangent of 0 is 0.0.
The inverse hyperbolic tangent of 0.0086 is 0.008600212028075704.

Note that the parameter should be a valid number. The values may be either positive or negative.

Example Codes: Code Demonstrates an Error of the math.atanh() Method

import math

x=1
value=math.atanh(x)
print(f"The inverse hyperbolic tangent of {x} is {value}.")

Output:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    value=math.atanh(x)
ValueError: math domain error

Note that a TypeError exception may occur if the argument value is not a float.

Example Codes: Use the Equivalent of the math.atanh() Method

import math

x=0.8
value=math.atanh(x)
print(f"The inverse hyperbolic tangent of {x} is {value}.")

equation=0.5*math.log((1+x)/(1-x))
print(f"Using the equation, the inverse hyperbolic tangent of {x} is {equation}.")

Output:

The inverse hyperbolic tangent of 0.8 is 1.0986122886681098.
Using the equation, the inverse hyperbolic tangent of 0.8 is 1.0986122886681098.

You can use either method to calculate the inverse hyperbolic tangent of a number.

Musfirah Waseem avatar Musfirah Waseem avatar

Musfirah is a student of computer science from the best university in Pakistan. She has a knack for programming and everything related. She is a tech geek who loves to help people as much as possible.

LinkedIn

Related Article - Python Math

  • Python math.pow() Method
  • Python Math.erf() Method
  • Python Math.erfc() Method
  • Python Math.expm1() Method
  • Python Math.fabs() Method
  • Python Math.factorial() Method