[关闭]
@flyboy1995 2016-11-21T13:01:35.000000Z 字数 3809 阅读 24

第九次作业


作业3.30


摘要

探究Lyapunov指数


背景

题目原文:
3.30:Investigate the Lyapunov exponent of the stadium billiard for several values of α. You can do this qualitatively by examining the behavior for only one set of initial conditions for each value of you consider, or more quantitatively by averaging over a range of initial conditions for each value of α.


正文

  1. import math
  2. import pylab as pl
  3. import numpy as np
  4. class qwer:
  5. def __init__(self,vx=1,vy=0,x=0,y=0.1,dt=0.01,dtt=0.00001,tt=100,x0=0.01):
  6. self.vx=[vx]
  7. self.vy=[vy]
  8. self.x=[x]
  9. self.y=[y]
  10. self.t=[0]
  11. self.dt=dt
  12. self.dtt=dtt
  13. self.tt=tt
  14. self.x0=x0
  15. def run(self):
  16. while self.t[-1]<self.tt:
  17. self.vx.append(self.vx[-1])
  18. self.vy.append(self.vy[-1])
  19. self.x.append(self.x[-1]+self.vx[-1]*self.dt)
  20. self.y.append(self.y[-1]+self.vy[-1]*self.dt)
  21. self.t.append(self.t[-1]+self.dt)
  22. while self.x[-1]>self.x0 and math.sqrt((self.x[-1]-self.x0)**2+self.y[-1]**2)>1:
  23. while math.sqrt((self.x[-1]-self.x0)**2+self.y[-1]**2)>1:
  24. self.x[-1]=self.x[-1]-self.vx[-1]*self.dtt
  25. self.y[-1]=self.y[-1]-self.vy[-1]*self.dtt
  26. self.t[-1]=self.t[-1]-self.dtt
  27. else:
  28. temp=(self.vx[-1]*(self.x[-1]-self.x0)+self.vy[-1]*self.y[-1])/((self.x[-1]-self.x0)**2+self.y[-1]**2)
  29. self.vx[-1]=self.vx[-1]-2*temp*(self.x[-1]-self.x0)
  30. self.vy[-1]=self.vy[-1]-2*temp*self.y[-1]
  31. while self.x[-1]<-self.x0 and math.sqrt((self.x[-1]+self.x0)**2+self.y[-1]**2)>1:
  32. while math.sqrt((self.x[-1]+self.x0)**2+self.y[-1]**2)>1:
  33. self.x[-1]=self.x[-1]-self.vx[-1]*self.dtt
  34. self.y[-1]=self.y[-1]-self.vy[-1]*self.dtt
  35. self.t[-1]=self.t[-1]-self.dtt
  36. else:
  37. temp=(self.vx[-1]*(self.x[-1]+self.x0)+self.vy[-1]*self.y[-1])/((self.x[-1]+self.x0)**2+self.y[-1]**2)
  38. self.vx[-1]=self.vx[-1]-2*temp*(self.x[-1]+self.x0)
  39. self.vy[-1]=self.vy[-1]-2*temp*self.y[-1]
  40. while -self.x0<self.x[-1]<self.x0 and (self.y[-1]>1 or self.y[-1]<-1):
  41. while self.y[-1]>1 or self.y[-1]<-1:
  42. self.x[-1]=self.x[-1]-self.vx[-1]*self.dtt
  43. self.y[-1]=self.y[-1]-self.vy[-1]*self.dtt
  44. self.t[-1]=self.t[-1]-self.dtt
  45. else:
  46. self.vy[-1]=-self.vy[-1]
  47. def show_phase_space(self):
  48. temp_x=[]
  49. temp_y=[]
  50. temp_vx=[]
  51. for i in range(len(self.y)):
  52. if math.fabs(self.y[i])<0.001:
  53. temp_y.append(self.y[i])
  54. temp_x.append(self.x[i])
  55. temp_vx.append(self.vx[i])
  56. pl.plot(temp_x,temp_vx,'.',label="dtt=%f"%self.dtt)
  57. pl.legend(loc='center right',frameon=True)
  58. pl.xlabel("x")
  59. pl.ylabel("$V_x$")
  60. pl.title("stadium billiard:$\delta$=%.3f"%self.x0)
  61. pl.xlim(-1,1)
  62. pl.grid(True)
  63. pl.show()
  64. def show_trajectory(self):
  65. pl.plot(self.x,self.y,label="dtt=%f"%self.dtt)
  66. pl.legend(loc='upper right',frameon=True)
  67. pl.title("sadium billiard trajectory $\delta$=%.3f"%self.x0)
  68. pl.xlabel("x")
  69. pl.ylabel("y")
  70. pl.grid(True)
  71. pl.xlim(-1.5,1.5)
  72. class lyapunov(qwer):
  73. def cal(self):
  74. self.divg=[]
  75. self.lndivg=[]
  76. self.temp1x=[]
  77. self.temp1y=[]
  78. self.temp1t=[]
  79. self.temp2x=[]
  80. self.temp2y=[]
  81. self.temp2t=[]
  82. self.tempt=[]
  83. self.initial_seperation=0.00001
  84. a=qwer(y=0.1)
  85. a.run()
  86. self.temp1x=a.x
  87. self.temp1y=a.y
  88. self.temp1t=a.t
  89. a=qwer(y=0.1-self.initial_seperation)
  90. a.run()
  91. self.temp2x=a.x
  92. self.temp2y=a.y
  93. self.temp2t=a.t
  94. tmp=min(len(self.temp1x),len(self.temp2x))
  95. for i in range(tmp):
  96. self.divg.append(math.sqrt((self.temp1x[i]-self.temp2x[i])**2+(self.temp1y[i]-self.temp2y[i])**2))
  97. self.lndivg.append(math.log(self.divg[i]))
  98. self.tempt.append(max(self.temp1t[i],self.temp2t[i]))
  99. def show_divergence(self):
  100. pl.plot(self.tempt,self.lndivg,label="initial seperation=%f"%self.initial_seperation)
  101. pl.title("divergence of two trajectories:$\delta$=%.4f"%self.x0)
  102. pl.xlabel("time")
  103. pl.ylabel("ln($\Delta R$)")
  104. pl.legend(loc="lower right",frameon=True)
  105. tt=[]
  106. dd=[]
  107. for i in range(4000):
  108. tt.append(self.tempt[i])
  109. dd.append(self.lndivg[i])
  110. z=np.polyfit(tt,dd,1)
  111. p=np.poly1d(z)
  112. print(p)
  113. linspx=np.linspace(0,50)
  114. linspy=z[0]*linspx+z[1]
  115. pl.plot(linspx,linspy)
  116. b=lyapunov()
  117. b.cal()
  118. b.show_divergence()

结论

可以看出α不同时,Lyapunov指数截然不同。α越小时,曲线越密集,说明系统经历了更多的状态。

致谢

感谢秦大粤和徐秋豪同学。

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