Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def dist(angle,m_prop):
  4. # constants
  5. n=1000 # number of time steps to simulate
  6. rho=1.225 # kg/m^3
  7. g=-9.8 # m/s^2
  8. start=0.0 # seconds
  9. end=10 # seconds
  10. initial_height=5
  11.  
  12. #insert loop
  13. initial_v=1500 * (m_prop/65)**0.45
  14. # object
  15. A=.8 # surface area m^2
  16. C=1.4 # drag coefficient
  17. mass=65 # mass of object in kg
  18.  
  19. # parameters of simulation
  20. radians=np.radians(angle)
  21.  
  22. #initalize state variables
  23. t=np.linspace(start,end,n+1)
  24. vx=np.zeros(n+1)
  25. vy=np.zeros(n+1)
  26. x=np.zeros(n+1)
  27. y=np.zeros(n+1)
  28.  
  29. y[0]=initial_height
  30. vx[0]=initial_v*np.cos(radians)
  31. vy[0]=initial_v*np.sin(radians)
  32.  
  33. # begin simulation
  34. for j in range(1,n+1):
  35. if y[j-1]<=0:
  36. vx[j]=0
  37. vy[j]=0
  38. y[j]=0
  39. x[j]=x[j-1]
  40. else:
  41. # the following code is _corrected_ from the wrong math
  42. v = np.sqrt( vx[ j-1 ]**2 + vy[ j-1 ]**2 )
  43. ax = -( 0.5*rho*C*A/mass ) * v**2 * ( vx[ j-1 ] / v )
  44. ay = g - ( 0.5*rho*C*A/mass ) * v**2 * ( vy[ j-1 ] / v )
  45. dt=t[j]-t[j-1]
  46. vx[j]=vx[j-1]+ax*dt
  47. vy[j]=vy[j-1]+ay*dt
  48. x[j]=x[j-1]+vx[j]*dt
  49. y[j]=y[j-1]+vy[j]*dt
  50. if y[j]<=0:
  51. y[j]=0
  52. x[j]=x[j-1]
  53. vx[j]=0
  54. vy[j]=0
  55. return x[n]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement