tanh()

tanh(x) returns hyperbolic tangent of x , the input number x is in radian.
``````import math
print(math.tanh(-5))    # -0.9999092042625951
print(math.tanh(-1))    # -0.7615941559557649
print(math.tanh(-0.9))  # -0.7162978701990244
print(math.tanh(0))     # 0.0
print(math.tanh(0.9))   # 0.7162978701990244
print(math.tanh(1))     # 0.7615941559557649
print(math.tanh(5))     # 0.9999092042625951``````
Note that all the inputs are in radian.

Inputs in degree

We can convert radian value to degree and use the same
``````import math
in_degree = 50
print(math.tanh(in_redian)) # 0.7027254303610717``````

Drawing graph of tanh()

We will use Matplotlib to generate graph of tanh
``````import matplotlib.pyplot as plt
x=[]
y=[]
i=-10
while (i<=10):
x.append(i)
y.append(math.tanh(i))
i=i+0.1
plt.plot(x,y)
plt.axvline(x=0.00,linewidth=2, color='#f1f1f1')
plt.axhline(y=0.00,linewidth=2, color='#f1f1f1')
plt.grid(linestyle='-',
linewidth=0.5,color='#f1f1f1')
plt.show()``````
Subscribe to our YouTube Channel here

Subscribe

* indicates required
Subscribe to plus2net

plus2net.com