@74849b
2017-02-28T13:31:58.000000Z
字数 2226
阅读 997
problem 3.31
We consider a problem of a ball moving without friction on a perfect billiard table.Between collisions the velocity is constant so we have
import matplotlib.pyplot as pltimport numpy as npimport mathclass tabel:def__init__(self,x_0=0.2,y_0=0,vx_0=-0.2,vy_0=-0.5,dt_1=0.001,total_time=1000):self.x=[x_0]self.y=[y_0]self.vx=[vx_0]self.vy=[vy_0]self.dt=dt_1self.time=total_timeself.t=[0]def calculate(self):for i in range(int(self.time/self.dt)):self.x.append(self.x[i]+self.vx[i]*self.dt)self.y.append(self.y[i]+self.vy[i]*self.dt)self.vx.append(self.vx[i])self.vy.append(self.vy[i])if ((self.x[i+1]**2+self.y[i+1]**2>1):X=(self.x[i]+self.x[i+1])/2Y=(self.y[i]+self.y[i+1])/2x1=X/(X**2+Y**2)**0.5y1=Y/(X**2+Y**2)**0.5self.vx[i+1]=(1-2*x1**2)*self.vx[i]-2*x1*y1*self.vy[i]self.vy[i+1]=(1-2*y1**2)*self.vy[i]-2*x1*y1*self.vx[i]if X**2+Y**2>1:self.x[i+1]=Xself.y[i+1]=Ycontinueelse:self.x[i]=Xself.y[i]=Ycontinuex_1=[-1]y_1=[0]x_2=[-1]y_2=[0]dx=0.0001def bound(self):for k in range(20000):x_1.append(x_1[k]+dx)y_1.append((1-x_1[k+1]**2)**0.5)x_2.append(x_2[k]+dx)y_2.append(-(1-x_2[k+1]**2)**0.5)def show_results(self):plt.plot(self.x,self.y,'--',label='trajectory')plt.plot(x_1,y_1,'--',label='bound')plt.plot(x_2,y_2,'--',label='bound')plt.xlabel(u'x')plt.ylabel(u'y')a=tabel()a.calculate()a.show_results()b=tabelb.bound()b.show_results()plt.show()
the results:for t=50,100,1000
*斜体文本*the corresponding phase:

the equation is
if ((self.x[i+1]**2/4+self.y[I+1]**2)>1):X=(self.x[i]+self.x[i+1])/2Y=(self.y[i]+self.y[i+1])/2x1=(X/2)/(X**2/4+Y**2)**0.5x2=Y/(X**2/4+Y**2)**0.5self.vx[i+1]=(1-2*x1**2)*self.vx[i]-2*x1*y1*self.vy[i]self.vy[i+1]=(1-2*y1**2)*self.vy[i]-2*x1*y1*self.vx[i]
for t=100,1000,7000:
the phase:

for t=100,1000,5000
