初级
计算24个向量的和并绘制
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from math import sin, cos, pi
vs = [(sin(pi*t/6), cos(pi*t/6), 1.0/3) for t in range(0, 24)]
v_sum = (sum(v[0] for v in vs), sum(v[1] for v in vs), sum(v[2] for v in vs))
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
current = (0, 0, 0)
for v in vs:
ax.quiver(current[0], current[1], current[2], v[0], v[1], v[2],
arrow_length_ratio=0.1, color='blue', alpha=0.5)
current = (current[0]+v[0], current[1]+v[1], current[2]+v[2])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.title('24个向量首尾相连')
plt.tight_layout()
plt.show()
print(f"向量和 = {v_sum}")
示例
输入
solve()
期望输出
输出结果
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199