Home » Python

math.acosh() method with example in Python

Python math.acosh() method: Here, we are going to learn about the math.acosh() method with example in Python.
Submitted by IncludeHelp, on April 23, 2019

Python math.acosh() method

math.acosh() method is a library method of math module, it is used to get the hyperbolic arc cosine of the given number in radians, it accepts a number and returns hyperbolic arc cosine.

Note: math.acosh() method accepts only numbers (positive integer or float greater than or equal to 1), if we provide a negative value it returns a ValueError"ValueError: math domain error", and if we provide anything else except the number, it returns error TypeError"TypeError: a float is required".

Syntax of math.acosh() method:

    math.acosh(x)

Parameter(s): x – is the number whose hyperbolic arc cosine to be calculated.

Return value: float – it returns a float value that is the hyperbolic arc cosine value of the number x.

Example:

    Input:
    x = 1.5

    # function call
    print(math.acosh(x))

    Output:
    0.9624236501192069

Python code to demonstrate example of math.acosh() method

# Python code to demonstrate example of 
# math.acosh() method

# importing math module
import math 

# number 
x = 1
print("math.acosh(",x,"): ", math.acosh(x))

x = 1.5
print("math.acosh(",x,"): ", math.acosh(x))

x = 5
print("math.acosh(",x,"): ", math.acosh(x))

x = 15.45
print("math.acosh(",x,"): ", math.acosh(x))

Output

math.acosh( 1 ):  0.0
math.acosh( 1.5 ):  0.9624236501192069
math.acosh( 5 ):  2.2924316695611777
math.acosh( 15.45 ):  3.429707205929454

ValueError example

# Python code to demonstrate example of 
# math.acosh() method with exception

# importing math module
import math 

# number 
x = -1
print("math.acosh(",x,"): ", math.acosh(x))

Output

Traceback (most recent call last):
  File "/home/main.py", line 9, in <module>
    print("math.acosh(",x,"): ", math.acosh(x))
ValueError: math domain error

TypeError example

# Python code to demonstrate example of 
# math.acosh() method with exception

# importing math module
import math 

# number 
x = "2.5"
print("math.acosh(",x,"): ", math.acosh(x))

Output

Traceback (most recent call last):
  File "/home/main.py", line 9, in <module>
    print("math.acosh(",x,"): ", math.acosh(x))
TypeError: a float is required


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.