关于Python的情节不正确

2024-06-24 12:40:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在没有空气阻力的情况下,绘制发射角为15度、30度、45度、60度和75度的弹丸轨迹,但是我在获取所述角度的轨迹图时遇到问题。我的代码如下(注意我需要使用数值方法)

import numpy as np
import matplotlib.pylab as plt

ang = [15, 30, 45, 60, 75] # angles
dt = 0.1 # time step
C = 0.0 #drag coeff.
g = 9.8 # accel. due to gravity
Vx = 700*np.cos(ang) #Vx component
Vy = 700*np.sin(ang) #Vy component
V0 = 700

x = [0]
y = [0]
n = 0

while y[n]>=0:

    Fx = -((C * V0 * Vx * (dt**2)/2))
    Fy = ((-g*(dt**2))/2) - ((C * V0 * Vy * (dt**2))/2)

    y.append(y[n] + dt*Fy)
    x.append(x[n] + dt*Fx)

    n += 1

plt.plot(x,y)
plt.show()

非常感谢您的帮助


Tags: import轨迹asnpdtpltcomponentfx