Python math.atanh() method is a library method of the math module, and it is used to get the hyperbolic arctangent of the given number in radians, it accepts a number and returns hyperbolic arctangent.
Note: math.atanh() method accepts only numbers, if we provide any number which is not in the range it returns a ValueError – “ValueError: math domain error”, if we provide anything else except the number, it returns error TypeError – “TypeError: a float is required”.
math.atanh(x)
x
– is the number whose hyperbolic arc tangent to be calculated.
import math
x = .99
print(math.atanh(x))
Output:
2.6466524123622457
Write a program to show the working of the atanh() method in Python.
import math
a1 = 0.7
b1 = 0.99
c1 = 0.35
d1 = 0.55
print("Value for parameter ", a1, " is ", math.atanh(a1))
print("Value for parameter ", b1, " is ", math.atanh(b1))
print("Value for parameter ", c1, " is ", math.atanh(c1))
print("Value for parameter ", d1, " is ", math.atanh(d1))
Output:
Value for parameter 0.7 is 0.8673005276940532
Value for parameter 0.99 is 2.6466524123622457
Value for parameter 0.35 is 0.3654437542713961
Value for parameter 0.55 is 0.6183813135744636
In this example, we have seen that by passing the valid parameter which is different for different examples, we get the desired atanh() method solution, which is the hyperbolic tangent value of the parameter.
Write the program to pass a value out of range from the atanh() Function and display the output.
import math
q = "M"
print(math.atanh(d))
Output:
TypeError: must be a real number, not str
In this example, we’ve seen that by passing a parameter which is not of number type, the Function throws an error.
Python asinh() function allows you to find a Trigonometric Hyperbolic ArcSine of the numeric values. Let’s use with Python list and tuple.
# app.py
import math
Tup = (21, 11, 19, -46, 30)
Lis = [-15, 25, -32.5, -45.95, 15.64]
print('Python Hyperbolic Arc Sine of Positive Number = %.2f' % math.asinh(21))
print('Python Hyperbolic Arc Sine of Negative Number = %.2f' % math.asinh(-11))
print('Python Hyperbolic Arc Sine of Tuple Item = %.2f' % math.asinh(Tup[3]))
print('Python Hyperbolic Arc Sine of List Item = %.2f' % math.asinh(Lis[2]))
print('Python Hyperbolic Arc Sine of Multiple Numbers = %.2f' %
math.asinh(22 + 49 - 27))
print('Python Hyperbolic Arc Sine of String Value = ', math.asinh('Hello'))
Output
python3 app.py
Python Hyperbolic Arc Sine of Positive Number = 3.74
Python Hyperbolic Arc Sine of Negative Number = -3.09
Python Hyperbolic Arc Sine of Tuple Item = -4.52
Python Hyperbolic Arc Sine of List Item = -4.17
Python Hyperbolic Arc Sine of Multiple Numbers = 4.48
Traceback (most recent call last):
File "app.py", line 15, in <module>
print('Python Hyperbolic Arc Sine of String Value = ', math.asinh('Hello'))
TypeError: must be real number, not str
First, we used the asinh Function directly on both the Positive integer and negative integer. The following statements find the hyperbolic arcsine of the corresponding values.
Next, We used the asinh() Function on Tuple and List items. If you observe the above output, the asinh() function is working correctly on them.
At last, we have passed asinh() Function on the string value, and it returns TypeError as output.
Thanks for reading !
#python