[关闭]
@oliver1995 2017-05-07T13:17:40.000000Z 字数 1414 阅读 800

Exercise_05:The Trajectory of a Cannon Shell

Abstract

  • use python to do homework 2.6

Background

  • Use the Euler method to calculate cannon shell trajectories,ignoring both air drag and the effect of air density.

Main body

Analysis:



so:




This is primary code:

  1. import pylab as pl
  2. from math import *
  3. class cannon:
  4. def __init__(self,init_v=10,theta =60,
  5. init_x=0,init_y=0,time_step=0.01 ):
  6. self.vx = [init_v*cos(theta*2*pi/360)]
  7. self.vy = [init_v*sin(theta*2*pi/360)]
  8. self.x = [init_x]
  9. self.y = [init_y]
  10. self.t = [0]
  11. self.B_m = B_m
  12. self.dt = time_step
  13. def run(self):
  14. while self.y[-1]>=0:
  15. self.x.append(self.x[-1] + self.dt * self.vx[-1])
  16. self.y.append(self.y[-1] + self.dt * self.vy[-1])
  17. self.vy.append(self.vy[-1] - self.dt * 9.8 )
  18. def show_results(self):
  19. pl.plot(self.x, self.y,color="black",
  20. linestyle="-",label="60")
  21. pl.legend(loc='upper right')
  22. pl.xlabel('x(km)')
  23. pl.ylabel('y(km)')
  24. pl.ylim(0,4)
  25. pl.show()
  26. a = cannon()
  27. a.run()
  28. a.show_results()

And this is a picture, which shows three different launch angle.
image

Conclusion

Acknowledgement

Thanks for teacher cai's PPT.

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