Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # solution starts below
- # this line loads numpy and matplotlib - it has to be a part of your code
- %pylab notebook
- # Initialize Constants
- V0 = 50
- y0 = 1
- x0 = 0
- theta0 = 45*pi/180
- Cd = .35
- r = .23/(2*pi)
- A = pi*r**2
- m = .142
- #Setting step size (dt) and number of points
- n = 100
- t = 8
- dt = t/n
- #Creating Arrays
- x = zeros(n)
- y = zeros(n)
- vx = zeros(n)
- vy = zeros(n)
- theta = zeros(n)
- v = zeros(n)
- #Initializing conditions and finding trajectory
- def trajectory(x, y, vx, vy, theta, v, g, D):
- x[1] = x0
- y[1] = y0
- theta[1] = theta0
- vx[1] = V0*cos(theta[1])
- vy[1] = V0*sin(theta[1])
- v[1] = V0
- for i in range(1, n-1):
- vx[i+1] = vx[i] - ((cos(theta[i])*.5*D*Cd*A*v[i]**2)/m)*dt #Change in vx due to horizontal component of air resistance
- vy[i+1] = vy[i] - ((sin(theta[i])*.5*D*Cd*A*v[i]**2)/m)*dt - g*dt #Change in vy due to vertical component of air resistance (and gravity)
- x[i+1] = x[i] + vx[i]*dt
- y[i+1] = y[i] + vy[i]*dt
- theta[i+1] = math.atan(vy[i+1]/vx[i+1])
- v[i+1] = sqrt(vx[i+1]**2+vy[i+1]**2)
- if(y[i+1] < 0):
- y[i+1] = 0
- vy[i+1] = 0
- figure()
- trajectory(x,y,vx,vy,theta,v,9.81,0)
- plot(x,y,marker='o')
- trajectory(x,y,vx,vy,theta,v,9.803,1.2)
- plot(x,y,marker='o')
- trajectory(x,y,vx,vy,theta,v,9.796,0.96)
- plot(x,y,marker='o')
- grid()
- xlabel('Horizontal Displacement')
- ylabel('Vertical Displacement')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement