[关闭]
@XF 2016-10-16T15:29:19.000000Z 字数 1553 阅读 110

第五次作业


题目2.6

Use the Euler method to calculate cannon shell trajectories ignoring both air drag and effect of air density (actually,ignoring the former automatically rules out the latter).Compare your results with those in Figure 2.4,and with the exact solution.

一、摘要

用Euler法解二元二阶常微分方程组。计算一个斜抛运动。
忽略空气阻力和空气密度的影响,计算精确解并与图2.4比较。
图2.4

二、背景介绍

对于二阶的牛顿方程:


设速度
则可以把方程组降阶为4元一阶方程组
常微分方程组:




然后便可用Euler法解这个方程组

三、正文

  1. import pylab
  2. from math import sqrt
  3. from math import cos
  4. from math import sin
  5. from math import pi
  6. class Euler2Dsimulation:
  7. def __init__(self,speed,theta,timestep=0.01):
  8. self._timestep=timestep
  9. self._x=[0]
  10. self._y=[0]
  11. self._vx=[speed*cos(theta)]
  12. self._vy=[speed*sin(theta)]
  13. self.g=9.8
  14. self.calculate()
  15. self.plot()
  16. def _accelerate(self,x,y,vx,vy):
  17. ansax=0
  18. ansay=-self.g
  19. return (ansax,ansay)
  20. def calculate(self):
  21. while self._y[-1]>=0:
  22. self._x.append(self._x[-1]+self._vx[-1]*self._timestep)
  23. self._y.append(self._y[-1]+self._vy[-1]*self._timestep)
  24. (ax,ay)=self._accelerate(self._x[-1],self._y[-1],self._vx[-1],self._vy[-1])
  25. self._vx.append(self._vx[-1]+self._vx[-1]*self._timestep*ax)
  26. self._vy.append(self._vy[-1]+self._timestep*ay)
  27. def plot(self):
  28. pylab.plot(self._x, self._y)
  29. pylab.xlabel('x ($m$)')
  30. pylab.ylabel('y ($m$)')
  31. Euler2Dsimulation(700,pi/4)
  32. Euler2Dsimulation(700,pi/6)
  33. Euler2Dsimulation(700,pi/3)
  34. pylab.show()

四、结论

如图

五、致谢

感谢杜威同学在写ptyhon程序方面的帮助。感谢蔡浩老师。

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