Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def dist(angle,m_prop):
- # constants
- n=1000 # number of time steps to simulate
- rho=1.225 # kg/m^3
- g=-9.8 # m/s^2
- start=0.0 # seconds
- end=10 # seconds
- initial_height=5
- #insert loop
- initial_v=1500 * (m_prop/65)**0.45
- # object
- A=.8 # surface area m^2
- C=1.4 # drag coefficient
- mass=65 # mass of object in kg
- # parameters of simulation
- radians=np.radians(angle)
- #initalize state variables
- t=np.linspace(start,end,n+1)
- vx=np.zeros(n+1)
- vy=np.zeros(n+1)
- x=np.zeros(n+1)
- y=np.zeros(n+1)
- y[0]=initial_height
- vx[0]=initial_v*np.cos(radians)
- vy[0]=initial_v*np.sin(radians)
- # begin simulation
- for j in range(1,n+1):
- if y[j-1]<=0:
- vx[j]=0
- vy[j]=0
- y[j]=0
- x[j]=x[j-1]
- else:
- # the following code is _corrected_ from the wrong math
- v = np.sqrt( vx[ j-1 ]**2 + vy[ j-1 ]**2 )
- ax = -( 0.5*rho*C*A/mass ) * v**2 * ( vx[ j-1 ] / v )
- ay = g - ( 0.5*rho*C*A/mass ) * v**2 * ( vy[ j-1 ] / v )
- dt=t[j]-t[j-1]
- vx[j]=vx[j-1]+ax*dt
- vy[j]=vy[j-1]+ay*dt
- x[j]=x[j-1]+vx[j]*dt
- y[j]=y[j-1]+vy[j]*dt
- if y[j]<=0:
- y[j]=0
- x[j]=x[j-1]
- vx[j]=0
- vy[j]=0
- return x[n]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement