Python弹弓模型
我试图模拟从弹弓发射的弹丸 这是我的代码:Python弹弓模型,python,numpy,scipy,physics,kinematics,Python,Numpy,Scipy,Physics,Kinematics,我试图模拟从弹弓发射的弹丸 这是我的代码: 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 *
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)
但它给了我一个对我来说毫无意义的情节:
我错过了什么?这些价值观不应该像他们那样表现出来,但就我个人而言,我不明白为什么
这可能是一些琐碎的事情,但我已经盯着这个太长时间了,所以我认为带上一双新的眼睛是最好的行动方式 我认为你的计算至少有两个主要问题:
X
-轴定义的。所以
vx0 = v0*cos(th) # not sin
vy0 = v0*sin(th) # not cos
z[3]=-g/m.
)这对我来说毫无意义。不要按质量划分这是一条美妙的抛物线轨道,发射角度似乎是水平的。有什么问题吗?你好,谢谢你的回复,作为我计算的一部分,我还必须做以下几点:你从0米的高度射击。在均匀平面(无障碍物、高程等)上的吊索射程是多少?确定岩石何时何地坠落,即当y=0时,t和x是多少。稍微调整一下角度,尽量扩大射程!但是当y从0变为-8000时,我怎么能找到t和x呢。这正是让我感到困扰的地方。你需要提高一点。@ReblochonMasque他正以60度的角度向上射击,与X轴成角度
th=30#设置发射角度
…谢谢你的回答,我已经按照你的指示编辑了我的方程式,现在绘图有意义了。至于除以质量,这是我的教授给我的方程:@nedimk994那么你的代码中还有一个错误。请参阅我的最后一个编辑。@ NeimkK99请考虑接受这个答案,如果它解决了你的问题。