python中acosh
Python math.acosh()方法 (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.
math.acosh()方法是数学模块的库方法,用于获取以弧度为单位的给定数字的双曲反余弦,它接受一个数字并返回双曲反余弦。
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".
注意: math.acosh()方法仅接受数字(正整数或浮点数大于或等于1),如果我们提供负值,它将返回ValueError – “ ValueError:math domain error” ,并且如果我们提供其他内容,则除外数字,它返回错误TypeError – “ TypeError:需要浮点数” 。
Syntax of math.acosh() method:
math.acosh()方法的语法:
math.acosh(x)
Parameter(s): x – is the number whose hyperbolic arc cosine to be calculated.
参数: x –是要计算其双曲反余弦的数字。
Return value: float – it returns a float value that is the hyperbolic arc cosine value of the number x.
返回值: float-它返回一个浮点值,该值是数字x的双曲反余弦值。
Example:
例:
Input:
x = 1.5
# function call
print(math.acosh(x))
Output:
0.9624236501192069
Python代码演示math.acosh()方法的示例 (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
ValueError示例
# 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
TypeError示例
# 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
翻译自: https://www.includehelp.com/python/math-acosh-method-with-example.aspx
python中acosh