Python 1st assignment PDF

Title Python 1st assignment
Course Physics
Institution Trinity College Dublin University of Dublin
Pages 8
File Size 286.8 KB
File Type PDF
Total Downloads 20
Total Views 144

Summary

Python assignment...


Description

JF COMPUTATIONAL LABORATORY REPORT SHEET The Trajectory of a Projectile with Friction Exercise 3: Projectile trajectories

Week:

Student Name: Laboratory Number:

Date: Student number:

This experiment allowed us to predict the time of flight, range and the optimum angle for a given initial velocity and launch angle, using python. In 1.2 we investigated projectile motion without friction and successfully determined the time of flight accurately to 3.45% percentage error.

[4]

In section 2.1, the optimum angle was determined to 450 in projectile motion on a horizontal plane without friction. It was also determined that the intial velocity does not effect the optimum angle. In section 2.2 we saw that according to the graph maxrange against initial velocity, the max range increases exponentially as the initial velocity increases. In section 3.1, the x versus t graph was not a straight-line graph due to the introduction of height dependent air drag. The range distance was also computed using python. The optimum angle was calculated to be 34.54540. It was not 450 as there was a height dependent air drag. The graph of maxrange against angle in 3.1 showed a slightly skewed graph to the left. This was due to the friction that the projectile would experience by the air. The range distance and maximum distance were computed to be the same, this may have been due to the angle π/5 and 34.54540 being quite similar. Another discrepancy seen was that the graph of maxrange against angle showed a max range of around 60m (with velocity of 40m/s) while the maximum range was calculated to be 87.3m (with velocity of 30m/s) therefore there may have being an error in the code regarding the computation of the maximum range. Section 1.2 Projectile motion without friction What is the time of flight for Initial velocity = 40 m/s the parameters shown on the Launch angle = /5 (=360) right ? Time of flight = 4.795s Choose another initial velocity (=0: # conditional loop continous until # projectile hits ground (occurs when y # becomes negative) x[i+1]=(2*x[i]-x[i-1]) # numerical integration to y[i+1]=(2*y[i]-y[i-1])-g*dt**2 # find x[i+1]and # y[i+1] i=i+1 # increment i for # next iteration # while loop has finished – no more indent x=x[0:i+1] # truncate x and y arrays y=y[0:i+1] return x,y,(dt*i),x[i] # return x,y,flight time, # range of projectile x, y, duration, distance = traj(angle,v0) print ('Distance:', distance) print ('Duration:', duration) v0=30 # initial speed at t=0 angle=math.pi/5 # math.pi=3.14 def traj(angle,v0): # function that computes trajectory vx0=math.cos(angle)*v0 # for some launch angle and # starting velocity vy0=math.sin(angle)*v0 #compute x and y component of # starting velocity x=np.zeros(len(time)) # initialize x,y arrays y=np.zeros(len(time)) x[0],y[0]=0,0 # projectile starts at (0,0) x[1],y[1]=x[0]+vx0*dt,y[0]+vy0*dt # second elements of # x and y are determined by # initial velocity i=1 while y[i]>=0: # conditional loop continous until # projectile hits ground (occurs when y # becomes negative)

x[i+1]=(2*x[i]-x[i-1]) # numerical integration to y[i+1]=(2*y[i]-y[i-1])-g*dt**2 # find x[i+1]and # y[i+1] i=i+1 # increment i for # next iteration # while loop has finished – no more indent x=x[0:i+1] # truncate x and y arrays y=y[0:i+1] return x,y,(dt*i),x[i] # return x,y,flight time, # range of projectile x, y, duration, distance = traj(angle,v0) print ('Distance:', distance) print ('Duration:', duration) n=5 angles=np.linspace(0,math.pi/2,n) maxrange=np.zeros(n) for i in range(n): x,y,duration,maxrange[i] = traj(angles[i],v0) angles=angles/2/math.pi*360 # convert rad to deg plt.plot(angles,maxrange) plt.xlabel("angle") plt.ylabel("maxrange") plt.show() print ("Optimum angle:",angles[np.where(maxrange==np.max(maxrange))]) n=100 angles=np.linspace(0,math.pi/2,n) maxrange=np.zeros(n) for i in range(n): x,y,duration,maxrange[i] = traj(angles[i],v0) angles=angles/2/math.pi*360 # convert rad to deg plt.plot(angles,maxrange) plt.xlabel("angle") plt.ylabel("maxrange") plt.show() n=100 invelocity=np.linspace(0,40,n) maxrange=np.zeros(n) angle=math.pi/5 for i in range(n): x,y,duration,maxrange[i] = traj(angle,invelocity[i]) plt.plot(invelocity,maxrange) plt.xlabel("initial velocity") plt.ylabel("maxrange") plt.show() v0=30 # initial speed at t=0 angle=math.pi/5 # math.pi=3.14

def traj_fric(angle,v0): # function that computes trajectory vx0=math.cos(angle)*v0 # for some launch angle and # starting velocity vy0=math.sin(angle)*v0 #compute x and y component of # starting velocity x=np.zeros(len(time)) # initialize x,y arrays y=np.zeros(len(time)) x[0],y[0]=0,0 # projectile starts at (0,0) x[1],y[1]=x[0]+vx0*dt,y[0]+vy0*dt # second elements of # x and y are determined by # initial velocity i=1 while y[i]>=0: # conditional loop continous until # projectile hits ground (occurs when y # becomes negative) f=0.5*(�)*(height-y[i])*dt x[i+1]=((2*x[i]-x[i-1]+(f*(x[i-1])))/(1+f)) # numerical integration to y[i+1]=((2*y[i]-y[i-1]+f*y[i])-g*dt**2)/(1+f) # find x[i+1]and # y[i+1] i=i+1 # increment i for # next iteration # while loop has finished – no more indent x=x[0:i+1] # truncate x and y arrays y=y[0:i+1] return x,y,(dt*i),x[i] # return x,y,flight time, # range of projectile x, y, duration, distance = traj(angle,v0) print ('Distance:', distance) print ('Duration:', duration) Distance: 87.30102386298924 Duration: 4.795 fig1=plt.figure() plt.plot(x,y) # plot y versus x plt.xlabel("x") plt.ylabel("y") plt.show()

n=100 angles=np.linspace(0,math.pi/2,n) maxrange=np.zeros(n) for i in range(n): x,y,duration,maxrange[i] = traj_fric(angles[i],v0) angles=angles/2/math.pi*360 # convert rad to deg print ("Optimum angle:",angles[np.where(maxrange==np.max(maxrange))]) v0=30 # initial speed at t=0 angle=0.60293 def traj_fric(angle,v0): # function that computes trajectory

vx0=math.cos(angle)*v0 # for some launch angle and # starting velocity vy0=math.sin(angle)*v0 #compute x and y component of # starting velocity x=np.zeros(len(time)) # initialize x,y arrays y=np.zeros(len(time)) x[0],y[0]=0,0 # projectile starts at (0,0) x[1],y[1]=x[0]+vx0*dt,y[0]+vy0*dt # second elements of # x and y are determined by # initial velocity i=1 while y[i]>=0: # conditional loop continous until # projectile hits ground (occurs when y # becomes negative) f=0.5*(�)*(height-y[i])*dt x[i+1]=((2*x[i]-x[i-1]+(f*(x[i-1])))/(1+f)) # numerical integration to y[i+1]=((2*y[i]-y[i-1]+f*y[i])-g*dt**2)/(1+f) # find x[i+1]and # y[i+1] i=i+1 # increment i for # next iteration # while loop has finished – no more indent x=x[0:i+1] # truncate x and y arrays y=y[0:i+1] return x,y,(dt*i),x[i] # return x,y,flight time, # range of projectile x, y, duration, distance = traj_fric(angle,v0) print ('Distance:', distance) print ('Duration:', duration) v0=40 γ=0.005 height=100 n=100 angles=np.linspace(0,math.pi/2,n) maxrange=np.zeros(n) for i in range(n): x,y,duration,maxrange[i] = traj_fric(angles[i],v0) angles=angles/2/math.pi*360 # convert rad to deg plt.plot(angles,maxrange) plt.xlabel("angle") plt.ylabel("maxrange") plt.show()...


Similar Free PDFs