[关闭]
@flyboy1995 2016-11-07T02:52:01.000000Z 字数 2927 阅读 38

第七次作业


作业3.13


摘要

计算混沌系统中两个单摆的运动差别,并得出Lyapunov指数.


背景

题目原文:
3.13:Write a program to calculate and compare the behavior of two,nearly identical pendulums.Use it to calculate the divergence of two nearby trajectories in the chaotic regime,as in Figure 3.7,and and make a qualitative estimate of the corresponding Lyapunov exponent from the slope of a plot of log(Δθ) as a function of t.


正文

关系式:




代码如下:

  1. import pylab as pl
  2. import numpy as np
  3. import math
  4. class chaotic_pendulums:
  5. def __init__(self,length=9.8,q=0.5,initial_theta=0.2,initial_theta1=(0.2-0.001),initial_omega=0,initial_omega1=0,F_d=1.2,Omega_d=2.0/3,step_time=0.04,total_time=120):
  6. self.theta=[initial_theta]
  7. self.omega=[initial_omega]
  8. self.theta1=[initial_theta1]
  9. self.omega1=[initial_omega1]
  10. self.d_theta=[math.log(0.001)]
  11. self.dt=step_time
  12. self.l=length
  13. self.q=q
  14. self.total_time=total_time
  15. self.fd=F_d
  16. self.omegad=Omega_d
  17. self.t=[0]
  18. self.n=int(total_time/step_time)
  19. def pendulum(self):
  20. while self.t[-1]<=self.total_time:
  21. temp_omega=self.omega[-1]+(-9.8/self.l*math.sin(self.theta[-1])-self.q*self.omega[-1]+self.fd*math.sin(self.omegad*self.t[-1]))*self.dt
  22. self.omega.append(temp_omega)
  23. temp_theta=self.theta[-1]+temp_omega*self.dt
  24. self.theta.append(temp_theta)
  25. temp_t=self.t[-1]+self.dt
  26. self.t.append(temp_t)
  27. def pendulum1(self):
  28. self.t=[0]
  29. while self.t[-1]<=self.total_time:
  30. temp_omega1=self.omega1[-1]+(-9.8/self.l*math.sin(self.theta1[-1])-self.q*self.omega1[-1]+self.fd*math.sin(self.omegad*self.t[-1]))*self.dt
  31. self.omega1.append(temp_omega1)
  32. temp_theta1=self.theta1[-1]+temp_omega1*self.dt
  33. self.theta1.append(temp_theta1)
  34. temp_t=self.t[-1]+self.dt
  35. self.t.append(temp_t)
  36. def cal_d_theta(self):
  37. while self.t[-1]<=self.total_time:
  38. temp_omega=self.omega[-1]+(-9.8/self.l*math.sin(self.theta[-1])-self.q*self.omega[-1]+self.fd*math.sin(self.omegad*self.t[-1]))*self.dt
  39. self.omega.append(temp_omega)
  40. temp_theta=self.theta[-1]+temp_omega*self.dt
  41. self.theta.append(temp_theta)
  42. temp_omega1=self.omega1[-1]+(-9.8/self.l*math.sin(self.theta1[-1])-self.q*self.omega1[-1]+self.fd*math.sin(self.omegad*self.t[-1]))*self.dt
  43. self.omega1.append(temp_omega1)
  44. temp_theta1=self.theta1[-1]+temp_omega1*self.dt
  45. self.theta1.append(temp_theta1)
  46. self.d_theta.append(math.log(math.fabs(temp_theta-temp_theta1)))
  47. temp_t=self.t[-1]+self.dt
  48. self.t.append(temp_t)
  49. def show_result(self):
  50. pl.plot(self.t,self.theta)
  51. pl.xlabel("time($s$)")
  52. pl.ylabel("angle($radians$)")
  53. def show_result1(self):
  54. _plot,=pl.plot(self.t,self.theta1)
  55. pl.xlabel("time($s$)")
  56. pl.ylabel("angle($radians$)")
  57. pl.legend([_plot],["initial_theta=0.2-0.001"])
  58. def show_result2(self):
  59. pl.plot(self.t,self.d_theta)
  60. pl.xlabel("time($s$)")
  61. pl.ylabel("log(d_theta)($radians$)")
  62. a=chaotic_pendulums()
  63. a.pendulum()
  64. a.show_result()
  65. b=chaotic_pendulums()
  66. b.pendulum1()
  67. b.show_result1()
  68. c=chaotic_pendulums()
  69. c.cal_d_theta()
  70. c.show_result2()
  71. z=np.polyfit(c.t,c.d_theta,1)
  72. p=np.poly1d(z)
  73. print(z)
  74. print(p)

结论

此处输入图片的描述此处输入图片的描述

Lyapunov指数为0.08508

致谢

感谢秦大粤同学的分享!

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