[关闭]
@rfhongyi 2016-11-09T03:36:23.000000Z 字数 5911 阅读 673

Exercise_05 :Exercise 2.6 & 2.8 from Book

Cannon Shell Trajectories

冉峰 弘毅班 2014301020064


Abstract


Background

From the Computational Physics we know the method of Euler.Now I want to take the Euler method into the projectile movement calculation:
Newton’s second law in two spatial dimensions :


Write each of these second-order equations as two firest-order differential equations:


Finite difference form:

There are some different situations


The Main Body

Code for ideal situation

  1. import pylab as pl
  2. import math
  3. class trajectories:
  4. def __init__(self,mass=10, time_step=0.1,total_time=13,\
  5. initial_velocity_x=50,initial_velocity_y=50,
  6. initial_x=0,initial_y=0,B2=0):
  7. self.v_x = [initial_velocity_x]
  8. self.v_y = [initial_velocity_y]
  9. self.v=[math.sqrt(pow(initial_velocity_x,2)+pow(initial_velocity_y,2))]
  10. self.x=[initial_x]
  11. self.y=[initial_y]
  12. self.t = [0]
  13. self.m = mass
  14. self.dt = time_step
  15. self.time = total_time
  16. self.B2=B2
  17. self.initial_velocity_x=initial_velocity_x
  18. self.initial_velocity_y=initial_velocity_y
  19. def run(self):
  20. _time = 0
  21. while(_time < self.time):
  22. self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
  23. self.v_x.append(self.v_x[-1]-(self.B2/self.m)\
  24. *self.v[-1]*self.dt*self.v_x[-1])
  25. self.v_y.append(self.v_y[-1]-10*self.dt-\
  26. (self.B2/self.m)*self.v[-1]*self.dt*self.v_y[-1])
  27. self.x.append(self.v_x[-1]*self.dt+self.x[-1])
  28. self.y.append(self.v_y[-1]*self.dt+self.y[-1])
  29. self.t.append(_time)
  30. _time += self.dt
  31. def show_results(self):
  32. font = {'family': 'serif',
  33. 'color': 'darkred',
  34. 'weight': 'normal',
  35. 'size': 16,}
  36. pl.plot(self.x, self.y,label='angle is %f'%(math.atan(self.\
  37. initial_velocity_y/self.initial_velocity_x)*180/math.pi))
  38. pl.title('Cannon shell trajectories', fontdict = font)
  39. pl.xlabel('x ($km$)')
  40. pl.ylabel('y ($km$)')
  41. pl.legend()
  42. pl.show()
  43. a = trajectories()
  44. a.run()
  45. a.show_results()

Result

Code for situation with air resistance

  1. import pylab as pl
  2. import math
  3. class trajectories:
  4. def __init__(self,mass=10, time_step=0.1,total_time=13,\
  5. initial_velocity_x=50,initial_velocity_y=50,
  6. initial_x=0,initial_y=0,B2=0.01):
  7. self.v_x = [initial_velocity_x]
  8. self.v_y = [initial_velocity_y]
  9. self.v=[math.sqrt(pow(initial_velocity_x,2)+pow(initial_velocity_y,2))]
  10. self.x=[initial_x]
  11. self.y=[initial_y]
  12. self.t = [0]
  13. self.m = mass
  14. self.dt = time_step
  15. self.time = total_time
  16. self.B2=B2
  17. self.initial_velocity_x=initial_velocity_x
  18. self.initial_velocity_y=initial_velocity_y
  19. def run(self):
  20. _time = 0
  21. while(_time < self.time):
  22. self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
  23. self.v_x.append(self.v_x[-1]-(self.B2/self.m)\
  24. *self.v[-1]*self.dt*self.v_x[-1])
  25. self.v_y.append(self.v_y[-1]-10*self.dt-\
  26. (self.B2/self.m)*self.v[-1]*self.dt*self.v_y[-1])
  27. self.x.append(self.v_x[-1]*self.dt+self.x[-1])
  28. self.y.append(self.v_y[-1]*self.dt+self.y[-1])
  29. self.t.append(_time)
  30. _time += self.dt
  31. def show_results(self):
  32. font = {'family': 'serif',
  33. 'color': 'darkred',
  34. 'weight': 'normal',
  35. 'size': 16,}
  36. pl.plot(self.x, self.y,label='angle is %f'%(math.atan(self.\
  37. initial_velocity_y/self.initial_velocity_x)*180/math.pi))
  38. pl.title('Cannon shell trajectories', fontdict = font)
  39. pl.xlabel('x ($km$)')
  40. pl.ylabel('y ($km$)')
  41. pl.legend()
  42. pl.show()
  43. a = trajectories()
  44. a.run()
  45. a.show_results()

Result


Code for situation is not a constant

  1. import pylab as pl
  2. import math
  3. class trajectories:
  4. def __init__(self,mass=10, time_step=0.1,total_time=20,\
  5. initial_velocity_x=150,initial_velocity_y=150,
  6. initial_x=0,initial_y=0,B2=0.01):
  7. self.v_x = [initial_velocity_x]
  8. self.v_y = [initial_velocity_y]
  9. self.v=[math.sqrt(pow(initial_velocity_x,2)+pow(initial_velocity_y,2))]
  10. self.x=[initial_x]
  11. self.y=[initial_y]
  12. self.t = [0]
  13. self.m = mass
  14. self.dt = time_step
  15. self.time = total_time
  16. self.B2=B2
  17. self.initial_velocity_x=initial_velocity_x
  18. self.initial_velocity_y=initial_velocity_y
  19. def run(self):
  20. _time = 0
  21. while(_time < self.time):
  22. self.v.append(math.sqrt(pow(self.v_x[-1],2)+pow(self.v_y[-1],2)))
  23. self.v_x.append(self.v_x[-1]-(self.B2/self.m)\
  24. *self.v[-1]*self.dt*self.v_x[-1])
  25. self.v_y.append(self.v_y[-1]-(4.03*pow(10,14)\
  26. /pow((self.y[-1]+6.371*pow(10,6)),2))*self.dt-\
  27. (self.B2/self.m)*self.v[-1]*self.dt*self.v_y[-1])
  28. #use '(4.03*pow(10,14)\pow((self.y[-1]+6.371*pow(10,6)),2))' to change '10'
  29. self.x.append(self.v_x[-1]*self.dt+self.x[-1])
  30. self.y.append(self.v_y[-1]*self.dt+self.y[-1])
  31. self.t.append(_time)
  32. _time += self.dt
  33. def show_results(self):
  34. font = {'family': 'serif',
  35. 'color': 'darkred',
  36. 'weight': 'normal',
  37. 'size': 16,}
  38. pl.plot(self.x, self.y,label='angle is %f'%(math.atan(self.\
  39. initial_velocity_y/self.initial_velocity_x)*180/math.pi))
  40. pl.title('Cannon shell trajectories', fontdict = font)
  41. pl.xlabel('x ($km$)')
  42. pl.ylabel('y ($km$)')
  43. pl.legend()
  44. pl.show()
  45. a = trajectories()
  46. a.run()
  47. a.show_results()

Result

figure5_7.png

We can see that the influence on the g is not a constant is very small when v not so big.


Conclusion


Thanks For

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注