📜  Python中的数学函数 |第 3 组(三角函数和角函数)(1)

📅  最后修改于: 2023-12-03 15:34:26.625000             🧑  作者: Mango

Python中的数学函数 | 第 3 组(三角函数和角函数)

在 Python 中,可以使用 math 模块来调用包含三角函数和角函数在内的基本数学函数。

本篇文章将会介绍以下函数:

  1. math.sin()
  2. math.cos()
  3. math.tan()
  4. math.atan()
  5. math.asin()
  6. math.acos()
  7. math.degrees()
  8. math.radians()
math.sin()

math.sin(x) 返回给定角度 x 的正弦值。

import math

result = math.sin(math.pi/2)
print(result)  # 输出结果为 1.0
math.cos()

math.cos(x) 返回给定角度 x 的余弦值。

import math

result = math.cos(math.pi)
print(result)  # 输出结果为 -1.0
math.tan()

math.tan(x) 返回给定角度 x 的正切值。

import math

result = math.tan(math.pi/4)
print(result)  # 输出结果为 0.9999999999999999(接近 1)
math.atan()

math.atan(x) 返回给定数字 x 的反正切值,结果以弧度表示。

import math

result = math.atan(1)
print(result)  # 输出结果为 0.7853981633974483(约等于 π/4)
math.asin()

math.asin(x) 返回给定数字 x 的反正弦值,结果以弧度表示。

import math

result = math.asin(0.5)
print(result)  # 输出结果为 0.5235987755982988(约等于 π/6)
math.acos()

math.acos(x) 返回给定数字 x 的反余弦值,结果以弧度表示。

import math

result = math.acos(0.5)
print(result)  # 输出结果为 1.0471975511965979(约等于 π/3)
math.degrees()

math.degrees(x) 将弧度转换为角度。

import math

result = math.degrees(math.pi/2)
print(result)  # 输出结果为 90.0
math.radians()

math.radians(x) 将角度转换为弧度。

import math

result = math.radians(90)
print(result)  # 输出结果为 1.5707963267948966(约等于 π/2)

这些函数可以在处理三角函数和角函数相关问题时发挥作用。通过对这些函数的理解和使用,可以优化和简化程序代码。