python中三角函数_Python中的三角函数
python中三角函数 Python三角函数/方法 (Python Trigonometric functions/methods)In python programming language, there are some of the built-in functions which are defined in math module – they can be used for Trig.
python中三角函数
Python三角函数/方法 (Python Trigonometric functions/methods)
In python programming language, there are some of the built-in functions which are defined in math module – they can be used for Trigonometric calculations, python has following Trigonometric functions, which are used to various purposes.
在python编程语言中 , 数学模块中定义了一些内置函数–它们可用于三角函数计算,python具有以下三角函数,可用于各种用途。
Python中的三角函数列表 (List of Trigonometric functions in Python)
Trigonometric functions | Description | Example |
---|---|---|
math.cos() | It returns the cosine of the number (in radians). | math.cos(x) |
math.sin() | It returns the sine of the number (in radians). | math.sin(x) |
math.tan() | It returns the tangent of the number in radians. | math.tan(x) |
math.acos() | It returns the arc cosine of the number in radians. | math.acos(x) |
math.asin() | It returns the arc sine of the number in radians. | math.asin(x) |
math.atan() | It returns the arc tangent of the number in radians. | math.atan(x) |
math.atan2() | It returns the result of the atan(y/x). | math.atan2(y,x) |
math.pypot() | Return the Euclidean norm, sqrt(x*x + y*y). | math.pypot(x,y) |
三角函数 | 描述 | 例 |
---|---|---|
math.cos() | 它返回数字的余弦(以弧度为单位)。 | math.cos(x) |
math.sin() | 它返回数字的正弦(以弧度为单位)。 | math.sin(x) |
math.tan() | 它以弧度形式返回数字的正切值。 | math.tan(x) |
math.acos() | 它返回弧度数的反余弦值。 | math.acos(x) |
math.asin() | 它返回弧度数的反正弦值。 | math.asin(x) |
math.atan() | 它返回弧度数的反正切值。 | math.atan(x) |
math.atan2() | 它返回atan(y / x)的结果 。 | math.atan2(y,x) |
math.pypot() | 返回欧几里得范数sqrt(x * x + y * y) 。 | math.pypot(x,y) |
Python代码演示所有三角函数的示例 (Python code to demonstrate example of all Trigonometric functions)
# Python code to demonstrate example
# of all Trigonometric functions
# importing math module
import math
# number
x = 0.75
# math.cos()
print("math.cos(",x,"): ", math.cos(x));
# math.sin()
print("math.sin(",x,"): ", math.sin(x));
# math.tan()
print("math.tan(",x,"): ", math.tan(x));
# math.acos()
print("math.acos(",x,"): ", math.acos(x));
# math.asin()
print("math.asin(",x,"): ", math.asin(x));
# math.atan()
print("math.atan(",x,"): ", math.atan(x));
y = 2
# math.atan2(y,x) = atan(y/x)
print("math.atan2(",y,",",x,"): ", math.atan2(y,x))
# math.hypot(x,y)
print("math.hypot(",x,",",y,"): ", math.hypot(x,y))
Output
输出量
math.cos( 0.75 ): 0.7316888688738209
math.sin( 0.75 ): 0.6816387600233341
math.tan( 0.75 ): 0.9315964599440725
math.acos( 0.75 ): 0.7227342478134157
math.asin( 0.75 ): 0.848062078981481
math.atan( 0.75 ): 0.6435011087932844
math.atan2( 2 , 0.75 ): 1.2120256565243244
math.hypot( 0.75 , 2 ): 2.1360009363293826
三角函数的例外 (Exceptions with Trigonometric functions)
There are two types of exceptions occur,
有两种类型的异常发生,
-
ValueError
ValueError
When we provide an invalid value (number), this exception occurs.
当我们提供无效的值(数字)时,将发生此异常。
-
TypeError
TypeError
When we provide a different type of values except a number, this exception occurs.
当我们提供数字以外的其他类型的值时,会发生此异常。
ValueError example
ValueError示例
# python code to demonstrate example of
# math.asin() method with an exception
# importing math module
import math
# number
a = 2
print("asin(",a,") is = ", math.asin(a))
Output
输出量
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("asin(",a,") is = ", math.asin(a))
ValueError: math domain error
TypeError example
TypeError示例
# python code to demonstrate example of
# math.cos() method with an exception
# importing math module
import math
# number
a = "2"
print("cos(",a,") is = ", math.cos(a))
Output
输出量
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("acos(",a,") is = ", math.acos(a))
TypeError: a float is required
翻译自: https://www.includehelp.com/python/trigonometric-functions.aspx
python中三角函数
更多推荐
所有评论(0)