[关闭]
@computationalphysics-2014301020090 2016-10-30T17:56:53.000000Z 字数 10847 阅读 216

The 7th homework

Problem3.12 The chaos of pendulum


Abstract

This article mainly discusses chaos in thee driven nonlinear pendulum and involves the solutions of exercise 3.12.The crucial method used in the article is Euler-Cromer method.


background

●Problem3.12.
In constructing the Poincare section in Figure 3.9 we plotted points only at times that were in phase with the drive force; that is, at times t≈2nπ/Ω, where n is an integer. At these values of t the driving force passed through zero. However, we could just as easily have chosen to make the plot at times corresponding to a maximum of the drive force, or at times π/4 out-of-phase with this force, etc. Construct the Poincare sections for these cases and compare them with Figure 3.9.

●Chaos theory is the field of study in mathematics that studies the behavior of dynamical systems that are highly sensitive to initial conditions—a response popularly referred to as the butterfly effect.Small differences in initial conditions (such as those due to rounding errors in numerical computation) yield widely diverging outcomes for such dynamical systems, rendering long-term prediction impossible in general. This happens even though these systems are deterministic, meaning that their future behavior is fully determined by their initial conditions, with no random elements involved. In other words, the deterministic nature of these systems does not make them predictable. This behavior is known as deterministic chaos, or simply chaos.

●In this paper, the relationship between angle and angular velocity is plotted, and the relationship between angular velocity and angle is drawn by simulating the method of flash display to calculate the chaotic phenomenon of nonlinear pendulum in physics textbooks. Figure, through these figures we can understand that chaotic phenomenon in the particle position is not completely random, but the average value with a certain law, specific to a certain point of relative fluctuations, these graphics can help us to compare the physical laws of intuitive Understanding, and thus appears to be crucial.


content

Now that we have a numerical method that is suitable for various of the simple pendulum, and armed with some understanding of what might or might not happen when dissipation, an external force, and/or nonlinearity is present, we are ready to take on a slightly more complicated and also more interesting situation. that is, we add all three ingredients which were previously discussed separately. Put all these ingredients together, we have the equation of motion :


we call this model for a nonlinear, dapmped, driven pendulum, the physical pendulum. It contains some very rich and interesting behaviors. However, as the equation can not be solved analytically, we have to turn to a numerical method. Under that case, the relevent differentlial equations are :


he Euler-Cromer method is used for numerical calculation:



given properiate initial value, we can easily simulate the process. Here, we have shown several pictures of interest.

●The initial code is used to test the basic functions of the program

code1:

  1. import matplotlib.pyplot as plt
  2. from math import *
  3. print 'Exercise 3.12 test V1.0'
  4. print 'Designed by roach'
  5. Constant_g=9.8
  6. Constant_l=9.8
  7. Constant_q=0.5
  8. Constant_Omegad=2.0/3.0
  9. dt = 0.001
  10. c_t = []
  11. c_theta = []
  12. c_omega = []
  13. def Calculate(Initial_theta,Initial_omega,c_t,c_theta,c_omega):
  14. c_theta.append(Initial_theta)
  15. c_omega.append(Initial_omega)
  16. c_t.append(0.0)
  17. print 'Initial_theta =',c_theta[0],'rad ',
  18. print 'Initial_omega =',c_omega[0],'rad/s ',
  19. print 'F_d =',F_d,'N ',
  20. for i in range(100000):
  21. c_omega.append(c_omega[i]-(sin(c_theta[i])+Constant_q*c_omega[i]+F_d*sin(Constant_Omegad*c_t[i]))*dt)
  22. c_theta.append(c_theta[i] + c_omega[i+1]*dt)
  23. c_t.append(c_t[i]+dt)
  24. if c_theta[-1]>pi:
  25. c_theta[-1]=c_theta[-1]-2*pi
  26. if c_theta[-1]<-pi:
  27. c_theta[-1]=c_theta[-1]+2*pi
  28. print 'Total steps =',i,' ',
  29. print 'dt =',dt
  30. return 0
  31. Initial_theta=0.2
  32. Initial_omega=0.0
  33. F_dlist=[0,0.5,1.2]
  34. for m in range(3):
  35. c_t = None
  36. c_theta = None
  37. c_omega = None
  38. c_t = []
  39. c_theta = []
  40. c_omega = []
  41. F_d=F_dlist[m]
  42. F_dstr=str(F_d)
  43. Calculate(Initial_theta,Initial_omega,c_t,c_theta,c_omega)
  44. plt.plot(c_t,c_theta,label='F_D = '+F_dstr+' (N)')
  45. plt.title('3.12 test')
  46. plt.xlabel('t (s)')
  47. plt.ylabel('theta (rad)')
  48. plt.legend()
  49. plt.show()

result1:混沌现象1.png

●Instead of plotting θ as a function of t, let us plot the angular velocity w as a function of θ. It is called Phase-space plot.

code2

  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: 胡胜勇
  4. Last modified on Mon Oct 31 00:10:24 2016
  5. """
  6. # basic packages needed
  7. # matplotlib - for plot 2D lines
  8. # numpy - for math
  9. import matplotlib.pyplot as plt
  10. import numpy as np
  11. import math
  12. # global var.
  13. g = 9.8
  14. l = 9.8
  15. q = 0.5
  16. OmgD = 2. / 3.
  17. # class Euler
  18. # use Euler METHOD to solve the pendulum
  19. # para. & var. :
  20. # theta0, omg0, t0 - initial angel & angular velocity & time
  21. # l, g, dt, time - length of string, gravity acceleration, time step size & total time
  22. # the time period of this pendulum - 1(s)
  23. class Nonlinear_Cromer(object):
  24. """docstring for Nonlinear_Cromer"""
  25. global g, l, q, OmgD
  26. def __init__(self, _FD = .0, _theta0 = 0.2, _omg0 = .0, _t0 = .0, _dt = 0.04, _time = 400.):
  27. self.FD = _FD
  28. self.theta = [_theta0]
  29. self.omg = [_omg0]
  30. self.t = [_t0]
  31. self.dt = _dt
  32. self.time = _time
  33. self.n = int(_time / _dt)
  34. self.THETA = []
  35. self.OMG = []
  36. self.T =[]
  37. # fun. calculate
  38. # n=0 means reset
  39. # n=1 means without reset
  40. def calculate(self):
  41. for i in range(self.n):
  42. domg = (-(g / l) * math.sin(self.theta[-1]) - q * self.omg[-1] + self.FD * math.sin(OmgD * self.t[-1])) * self.dt
  43. self.omg.append(self.omg[-1] + domg)
  44. dtheta = self.omg[-1] * self.dt
  45. temp_theta = self.theta[-1] + dtheta
  46. if temp_theta < - math.pi:
  47. self.theta.append(temp_theta + 2 * math.pi)
  48. elif temp_theta > math.pi:
  49. self.theta.append(temp_theta - 2 * math.pi)
  50. else:
  51. self.theta.append(temp_theta)
  52. self.t.append(self.t[-1] + self.dt)
  53. # print 'theta length:',len(self.theta)
  54. # fun. plotplot_phase_space
  55. # 去除了阶跃点之间的连线的相空间图
  56. def plot_phase_space(self, _ax, _color):
  57. l = []
  58. for i, j in enumerate(self.theta):
  59. if abs(j - self.theta[i-1]) > 6.:
  60. l.append(i)
  61. else:
  62. pass
  63. l = [i -1 for i in l]
  64. l = [-1] + l + [len(self.theta)]
  65. # print l,len(l)
  66. for i, j in enumerate(l):
  67. if i < (len(l) - 1):
  68. self.THETA.append(self.theta[j+1 : l[i + 1]])
  69. self.OMG.append(self.omg[j+1 : l[i + 1]])
  70. self.T.append(self.t[j+1 : l[i + 1]])
  71. # print len(self.THETA), len(self.OMG), len(self.T)
  72. _ax.plot(self.THETA[0], self.OMG[0], '-', color = _color,label = r'$F_D = %.1f$' % self.FD)
  73. for i in range(len(self.T)-1):
  74. _ax.plot(self.THETA[i+1], self.OMG[i+1], '-', color = _color)
  75. # plot:
  76. # ax1: theta vs time
  77. fig = plt.figure(figsize = (16., 5))
  78. ax1 = fig.add_subplot(121)
  79. ax2 = fig.add_subplot(122)
  80. comp = Nonlinear_Cromer(_FD = 0.5)
  81. comp.calculate()
  82. comp.plot_phase_space(ax1,'g')
  83. comp = Nonlinear_Cromer(_FD = 1.2)
  84. comp.calculate()
  85. comp.plot_phase_space(ax2,'r')
  86. for i in fig.axes:
  87. i.legend(fontsize=12,loc='upper right')
  88. # i.set_title(r'$\theta vs time$',fontsize=14)
  89. i.set_xlabel(r'$\theta (radians)$',fontsize=14)
  90. i.set_ylabel(r'$\omega (radians/s)$',fontsize=14)
  91. i.set_title(r'$Phase\quad Plot$'+r'$(q=\frac{1}{2}, l=g=9.8, \Omega_D=\frac{2}{3})$',fontsize=18)
  92. # ax1.set_title(r'$\theta\quad vs\quad time$'+r'$(q=\frac{1}{2}, l=g=9.8, \Omega_D=\frac{2}{3})$',fontsize=18)
  93. plt.show()

result2:混沌现象2.png

●we can also plot when

code3:

  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: 胡胜勇
  4. Last modified on Mon Oct 31 01:20:08 2016
  5. """
  6. # basic packages needed
  7. # matplotlib - for plot 2D lines
  8. # numpy - for math
  9. import matplotlib.pyplot as plt
  10. import numpy as np
  11. import math
  12. # global var.
  13. g = 9.8
  14. l = 9.8
  15. q = 0.5
  16. OmgD = 2. / 3.
  17. # class Euler
  18. # use Euler METHOD to solve the pendulum
  19. # para. & var. :
  20. # theta0, omg0, t0 - initial angel & angular velocity & time
  21. # l, g, dt, time - length of string, gravity acceleration, time step size & total time
  22. # the time period of this pendulum - 1(s)
  23. class Nonlinear_Cromer(object):
  24. """docstring for Nonlinear_Cromer"""
  25. global g, l, q, OmgD
  26. def __init__(self, _FD = .0, _theta0 = 0.2, _omg0 = .0, _t0 = .0, _dt = 0.04, _time = 8000.):
  27. self.FD = _FD
  28. self.theta = [_theta0]
  29. self.omg = [_omg0]
  30. self.t = [_t0]
  31. self.dt = _dt
  32. self.time = _time
  33. self.n = int(_time / _dt)
  34. self.THETA = []
  35. self.OMG = []
  36. self.T =[]
  37. # fun. calculate
  38. # n=0 means reset
  39. # n=1 means without reset
  40. def calculate(self):
  41. for i in range(self.n):
  42. domg = (-(g / l) * math.sin(self.theta[-1]) - q * self.omg[-1] + self.FD * math.sin(OmgD * self.t[-1])) * self.dt
  43. self.omg.append(self.omg[-1] + domg)
  44. dtheta = self.omg[-1] * self.dt
  45. temp_theta = self.theta[-1] + dtheta
  46. if temp_theta < - math.pi:
  47. self.theta.append(temp_theta + 2 * math.pi)
  48. elif temp_theta > math.pi:
  49. self.theta.append(temp_theta - 2 * math.pi)
  50. else:
  51. self.theta.append(temp_theta)
  52. self.t.append(self.t[-1] + self.dt)
  53. # print 'theta length:',len(self.theta)
  54. # fun. plotplot_phase_space
  55. # 去除了阶跃点之间的连线的相空间图
  56. def plot_phase_space(self, _ax, _phi,_lab):
  57. t = np.array([(i * OmgD - _phi) / np.pi / 2 for i in self.t])
  58. tempt = np.array([round(i) for i in t])
  59. tempt2 = t - tempt
  60. a = []
  61. for i, j in enumerate(tempt2):
  62. if abs(j) < 0.001:
  63. a.append(i)
  64. self.THETA = [self.theta[i] for i in a]
  65. self.OMG = [self.omg[i] for i in a]
  66. # print t, tempt, tempt2,a
  67. # print a
  68. _ax.plot(self.THETA, self.OMG, 'o',markersize = 3.3,color = 'r',label = r'$F_D = %.1f, \phi=$' % self.FD + _lab )
  69. # for i in range(len(self.T)-1):
  70. # _ax.plot(self.THETA[i+1], self.OMG[i+1], '-', color = _color)
  71. # plot:
  72. # ax1: theta vs time
  73. fig = plt.figure(figsize = (9.708, 6))
  74. ax1 = fig.add_subplot(221, xlim = (-4, 4))
  75. ax2 = fig.add_subplot(222, xlim = (-4, 4))
  76. ax3 = fig.add_subplot(223, xlim = (-4, 4))
  77. ax4 = fig.add_subplot(224, xlim = (-4, 4))
  78. comp = Nonlinear_Cromer(_FD = 1.2)
  79. comp.calculate()
  80. comp.plot_phase_space(ax1,0,'0')
  81. comp = Nonlinear_Cromer(_FD = 1.2)
  82. comp.calculate()
  83. comp.plot_phase_space(ax2,np.pi / 4,r'$\pi/4$')
  84. comp = Nonlinear_Cromer(_FD = 1.2)
  85. comp.calculate()
  86. comp.plot_phase_space(ax3,np.pi / 2,r'$\pi/2$')
  87. comp = Nonlinear_Cromer(_FD = 1.2)
  88. comp.calculate()
  89. comp.plot_phase_space(ax4, np.pi,r'$\pi$')
  90. for i in fig.axes:
  91. i.legend(fontsize=12,loc='best')
  92. # i.set_title(r'$\theta vs time$',fontsize=14)
  93. i.set_xlabel(r'$\theta (radians)$',fontsize=14)
  94. i.set_ylabel(r'$\omega (radians/s)$',fontsize=14)
  95. # i.set_title(r'$Poincare Section$'+r'$(q=\frac{1}{2}, l=g=9.8, \Omega_D=\frac{2}{3})$',fontsize=18)
  96. ax1.text(2,1.2,r'$Poincare Section$'+r'$(q=\frac{1}{2}, l=g=9.8, \Omega_D=\frac{2}{3})$'+'\n ' +r'$\Omega_Dt=2n\pi +\phi$',fontsize=18)
  97. plt.show()

result3:混沌现象3.png

Conclusion

It can be seen from the above calculation results that when the amplitude of the driving force is F_D = 0.5, the relationship between w and θ is relatively stable, that is, when taking a certain time, can determine the angular velocity at a certain angle, And the driving force is increased to 1.2, the relationship between the angle and the angular velocity is negative at a certain time, and the relationship between the angle and the angular velocity can not be uniquely determined, but it can be seen that these specific moments The relationship between the angle and angular velocity is always in accordance with certain laws of change, not completely random, this is the nature of the phenomenon of chaos.
the real physical model is usually a very complicated system, chaos can happend in various system. In this article, we have only shown the chaorotic behaviors in a nonlinear, damping, driveing pendulum, more are still to be seen.

Acknowledgement

references:
1: Cai Hao. https://github.com/caihao/computational_physics_whu.
2.Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris Meyers, and Dario Mitchell. How to think like a computer scientist—— Learning with Python: Interactive Edition 2.0.
3.Nicholas J.Giordano,Hisao Naknishi.Computational Physics(Second Edition).
[4]. Wikipedia contributors, "Bifurcation diagram," Wikipedia, The Free Encyclopedia, https://en.wikipedia.org/w/index.php?title=Bifurcation_diagram&oldid=680690451.

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