2023年3月21日 星期二

GPT3 寫的程式

 很不幸,在公司的電腦有許多限制,讓我無法執行這些 GPT3 所寫的程式,故先放在這邊。以下程式都是 GPT3 寫的,我還沒有測試過。


import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import math

# 設定恆星位置
star_pos = np.array([0, 0, 0])

# 設定行星軌道參數
a = 2 # 長軸半徑
b = 1 # 短軸半徑
theta = np.linspace(0, 2 * np.pi, 200) # 軌道角度
x = a * np.cos(theta) # 軌道 x 座標
y = b * np.sin(theta) # 軌道 y 座標

# 計算行星位置
planet_pos = np.array([x, y, np.zeros(len(x))]).T
for i in range(len(planet_pos)):
phi = math.radians(10 * i) # 每次繞行一圈增加 10
rotation_matrix = np.array([[math.cos(phi), -math.sin(phi), 0],
[math.sin(phi), math.cos(phi), 0],
[0, 0, 1]])
planet_pos[i] = rotation_matrix.dot(planet_pos[i]) + star_pos

# 繪製圖形
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(planet_pos[:, 0], planet_pos[:, 1], planet_pos[:, 2])
ax.scatter(star_pos[0], star_pos[1], star_pos[2], c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()


===

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

import numpy as np


# 粒子運動軌跡數據

x = [1, 2, 3, 4, 5]

y = [2, 3, 4, 5, 6]

z = [1, 2, 3, 4, 5]


# 繪製三維圖形

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.plot(x, y, z)


# 設置圖形參數

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')


# 顯示圖形

plt.show()


===