@c-xy
2016-10-16T15:55:27.000000Z
字数 1125
阅读 134
习题2.6
摘要
对于习题2.6,本文的主要工作是用Euler法求解二元二阶常微分方程组.
背景知识
本题的数值模拟源于以下微分方程组
import pylabfrom math import sqrtfrom math import cosfrom math import sinfrom math import piclass Euler2Dsimulation:def __init__(self,speed,theta,timestep=0.001):self._timestep=timestepself._x=[0]self._y=[0]self._vx=[speed*cos(theta)]self._vy=[speed*sin(theta)]self.g=9.8self.calculate()self.plot()def _accelerate(self,x,y,vx,vy):ansax=0ansay=-self.greturn (ansax,ansay)def calculate(self):while self._y[-1]>=0:self._x.append(self._x[-1]+self._vx[-1]*self._timestep)self._y.append(self._y[-1]+self._vy[-1]*self._timestep)(ax,ay)=self._accelerate(self._x[-1],self._y[-1],self._vx[-1],self._vy[-1])self._vx.append(self._vx[-1]+self._vx[-1]*self._timestep*ax)self._vy.append(self._vy[-1]+self._timestep*ay)def plot(self):pylab.plot(self._x, self._y)pylab.xlabel('x ($m$)')pylab.ylabel('y ($m$)')Euler2Dsimulation(700,pi/4)Euler2Dsimulation(700,pi/6)Euler2Dsimulation(700,pi/3)pylab.show()
结果展示
