AppDividend
Latest Code Tutorials

Python sinh() Function | Math.sinh() in Python Example

0

Python sinh() is an inbuilt method that is defined under the math module, which is used to find a hyperbolic sine of the given parameter in radians. For instance, if x is passed as a parameter in sinh() function (sinh(x)) it returns the hyperbolic sine value. We can use the math module by importing it.

Python sinh()

Python sinh() function is one of the Python Math function, which calculates the Trigonometric Hyperbolic Sine for the specified expression.

Syntax

math.sinh(var)

Here var is a variable of which hyperbolic sine we have to find.

Parameters

It takes one parameter var, which takes values of numeric datatype and throws TypeError if an argument is of any other data type is passed.

Return Value

The sinh() function returns a hyperbolic sine value of the number in the float datatype.

import math

var = 0.7
print(math.sinh(var))

Example programs on sinh() method in Python

Example 1: Write the program to show the working of the sinh() method in Python.

import math

a1 = 0.3
b1 = 0.9
c1 = 0.7
d1 = 0.2

print("Value for parameter ", a1, " is ", math.sinh(a1))
print("Value for parameter ", b1, " is ", math.sinh(b1))
print("Value for parameter ", c1, " is ", math.sinh(c1))
print("Value for parameter ", d1, " is ", math.sinh(d1))

Output

Value for parameter  0.3  is  0.3045202934471426
Value for parameter  0.9  is  1.0265167257081753
Value for parameter  0.7  is  0.7585837018395335
Value for parameter  0.2  is  0.201336002541094

In this example, we have seen that by passing the vaild parameter, which is different for different examples, we get the desired sinh() method solution, which is the hyperbolic sine value of the parameter.

Example 2: Write a program to pass the value out of range from the sinh() Function and display the output.

import math

x = 'q'
print(math.sinh(x))

Output

TypeError: must be 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 sinh() with list and tuple

See the following code.

import math

Tup = (11, 21, 3, -46, 5)
Lis = [-11, 21, -3.5, -46, 5]

print('Python Hyperbolic Sine value of Positive Number = %.2f' % math.sinh(11))
print('Python Hyperbolic Sine value of Negative Number = %.2f' % math.sinh(-21))

print('Python Hyperbolic Sine value of Tuple Item = %.2f' % math.sinh(Tup[3]))
print('Python Hyperbolic Sine value of List Item = %.2f' % math.sinh(Lis[2]))

print('Python Hyperbolic Sine value of Multiple Numbers = %.2f' %
      math.sinh(2 + 9 - 7))

print('Python Hyperbolic Sine value of String Value = ', math.sinh('AppDividend'))

Output

python3 app.py
Python Hyperbolic Sine value of Positive Number = 29937.07
Python Hyperbolic Sine value of Negative Number = -659407867.24
Python Hyperbolic Sine value of Tuple Item = -47480597103012241408.00
Python Hyperbolic Sine value of List Item = -16.54
Python Hyperbolic Sine value of Multiple Numbers = 27.29
Traceback (most recent call last):
  File "app.py", line 15, in <module>
    print('Python Hyperbolic Sine value of String Value = ', math.sinh('AppDividend'))
TypeError: must be real number, not str

First, we used the sinh() Function directly on both the Positive integer and negative integer.

Next, We used the sinh() Function on Python Tuple and List items.

Then, We used the sinh() Function directly on multiple values. Within the last statement, we tried the sinh Function on the String value, and it returns TypeError as output.

See also

Python degrees()

Python tan()

Python sin()

Python acosh()

Python asinh()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.