python用*画三角形_五点画图法三角函数

python用*画三角形_五点画图法三角函数在 Python 中 你可以使用 math 模块来计算三角函数的值 下面是一些基本的三角函数及其使用方法 1 正弦函数 sin x pythonimport mathprint sin 3 math sin 3 print sin 3 math sin 3 print sin 0 math sin 0 print sin math pi

在Python中,你可以使用`math`模块来计算三角函数的值。下面是一些基本的三角函数及其使用方法:

1. 正弦函数 `sin(x)`

python

import math

print("sin(3):", math.sin(3))

print("sin(-3):", math.sin(-3))

print("sin(0):", math.sin(0))

print("sin(math.pi):", math.sin(math.pi))

print("sin(math.pi/2):", math.sin(math.pi/2))

2. 余弦函数 `cos(x)`

python

import math

print("cos(3):", math.cos(3))

print("cos(-3):", math.cos(-3))

print("cos(0):", math.cos(0))

print("cos(math.pi):", math.cos(math.pi))

print("cos(2*math.pi):", math.cos(2*math.pi))

3. 正切函数 `tan(x)`

python

import math

print("tan(3):", math.tan(3))

print("tan(-3):", math.tan(-3))

print("tan(0):", math.tan(0))

print("tan(math.pi):", math.tan(math.pi))

print("tan(math.pi/2):", math.tan(math.pi/2))

print("tan(math.pi/4):", math.tan(math.pi/4))

4. 反正弦函数 `asin(x)`

python

import math

print("asin(1):", math.asin(1))

5. 反余弦函数 `acos(x)`

python

import math

print("acos(-1):", math.acos(-1))

6. 反正切函数 `atan(x)`

python

import math

print("atan(1):", math.atan(1))

7. 反正切函数 `atan2(y, x)`

python

import math

print("atan2(1, 1):", math.atan2(1, 1))

8. 角度转弧度 `radians(x)`

python

import math

print("radians(math.pi/2):", math.radians(math.pi/2))

9. 弧度转角度 `degrees(x)`

python

import math

print("degrees(math.pi/2):", math.degrees(math.pi/2))

10. 计算距离 `hypot(x, y)`

python

import math

print("hypot(3, 4):", math.hypot(3, 4))

如果你想在同一个图中绘制三角函数的图像,可以使用`matplotlib`库。下面是一个简单的例子:

python

import numpy as np

from matplotlib import pyplot as plt

x = np.linspace(-np.pi, np.pi, 256, endpoint=True)

y = np.sin(x)

z = np.cos(x)

plt.plot(x, y, color='blue', linewidth=1.0, linestyle='-')

plt.plot(x, z, color='red', linewidth=1.0, linestyle='-')

plt.xlim(-4, 4)

plt.xticks(np.linspace(-4, 4, 9, endpoint=True))

plt.ylim(-1, 1)

plt.yticks(np.linspace(-1, 1, 5, endpoint=True))

plt.show()

这段代码会创建一个6×8英寸的图像,并在其中绘制正弦和余弦函数的图像。

编程小号
上一篇 2026-03-17 16:36
下一篇 2026-03-17 16:28

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://sigusoft.com/bj/72350.html