0

我正在尝试模拟从弹弓发射弹丸。

这是我的代码:

from pylab import * 
import numpy as np
from scipy.integrate import odeint
import seaborn
## set initial conditions and parameters
g = 9.81            # acceleration due to gravity
th = 30            # set launch angle
th = th * np.pi/180.   # convert launch angle to radians
v0 = 10.0           # set initial speed
c = 0.5             # controls strength of air drag
d = 0.02 # diameter of the spherical rock
A = pi * (d/2)**2 #the cross-sectional area of the spherical rock
ro = 1.2041 #the density of the medium we are perfoming the launch in
m = 0.01 #mass

x0=0                # specify initial conditions
y0=0
vx0 = v0*sin(th)
vy0 = v0*cos(th)

## defining our model
def slingshot_model(state,time):
    z = zeros(4)    # create array to hold z vector
    z[0] = state[2] # z[0] = x component of velocity
    z[1] = state[3] # z[1] = y component of velocity
    z[2] = - c*A*ro/2*m*sqrt(z[0]**2 + z[1]**2)*z[0]         # z[2] = acceleration in x direction
    z[3] = -g/m - c*A*ro/2*m*sqrt(z[0]**2 + z[1]**2)*z[1]       # z[3] = acceleration in y direction
    return z

## set initial state vector and time array
X0 = [x0, y0, vx0, vy0]        # set initial state of the system
t0 = 0
tf = 4 #final time
tau = 0.05 #time step


# create time array starting at t0, ending at tf with a spacing tau
t = arange(t0,tf,tau)   

## solve ODE using odeint
X = odeint(slingshot_model,X0,t) # returns an 2-dimensional array with the 
                        # first index specifying the time and the
                        # second index specifying the component of
                        # the state vector

# putting ':' as an index specifies all of the elements for
# that index so x, y, vx, and vy are arrays at times specified 
# in the time array
x = X[:,0]  
y = X[:,1] 
vx = X[:,2] 
vy = X[:,3]

plt.rcParams['figure.figsize'] = [10, 10]
plot(x,y)

但它给了我这个对我来说没有意义的情节:

在此处输入图像描述

我错过了什么?价值观不应该像他们那样出来,但对于我的生活,我不明白为什么。

这可能是一件微不足道的事情,但我已经盯着这个太久了,所以我认为引入一组新的眼睛是最好的做法。

4

1 回答 1

1

我认为您的计算至少存在两个主要问题:

  1. 通常角度是相对于 -X轴定义的。所以

    vx0 = v0*cos(th) # not sin
    vy0 = v0*sin(th) # not cos
    
  2. 最重要的是,为什么要将自由落体的加速度除以g质量?(请参阅z[3] = -g/m...)这对我来说毫无意义。不要除以质量!

编辑:

  1. 根据您的评论和链接公式,很明显您的代码还存在第三个错误:空气阻力项应该与质量成反比

在此处输入图像描述

于 2018-05-29T05:33:22.190 回答