我正在尝试模拟从弹弓发射投射物的模型。
这是我的代码:
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)但它给了我一个对我来说没有意义的情节:

我遗漏了什么?价值观不应该像他们那样出现,但对于我的生活来说,我不明白为什么。
这可能是一些微不足道的事情,但我已经盯着它看了太久,所以我认为引入一组新的眼睛是最好的行动方案。
发布于 2018-05-29 13:33:22
我认为你的计算至少有两个主要问题:
X-axis来定义的。因此vx0 = v0*cos(th) # not sin vy0 = v0*sin(th) # not cos
g?(参见z[3] = -g/m...)这对我来说毫无意义。不要除以质量!编辑:
基于您的注释和链接公式,很明显,您的代码还存在第三个错误:空气阻力项应该与mass成反比(

https://stackoverflow.com/questions/50576540
复制相似问题