首先我們將theta作為橫坐標,omega作為縱坐標,同時變化F_D的參數(shù),比較這兩種情況下擺的混沌效應(yīng).
-q\frac{d\theta}{dt}+F_Dsin(\Omega_D t))
通過歐勒法得到代碼的設(shè)計方法:
for each time step i(beginning with i =1),calculate
\omega and \theta at time step i+1.
- sin\theta_i-q\omega_i+F_Dsin(\Omega_Dt_i)]\Delta t)
- 
- if \theta_{i+1} is out of the range[-pi,pi],add or substract 2pi to keep it in the range.
- 
- Repeat
代碼實現(xiàn)
def swing(self):
loop = True
i = 0
while(loop):
self.omega.append(self.omega[i] + (-self.g_l * math.sin(self.theta[i]) - self.q * self.omega[i] +
self.f_d * math.sin(self.omega_d * self.t[i])) * self.dt)
self.temp = self.theta[i] + self.omega[i + 1] * self.dt
if math.pi < self.temp:
self.temp -= 2 * math.pi
elif - math.pi > self.temp:
self.temp += 2 * math.pi
self.theta.append(self.temp)
self.t.append(self.t[i] + self.dt)
i += 1
if self.total_time < self.t[i]:
loop = False
Then we only plot omega versus theta only at times that are in phase with the driving force.
That is,we only display the point when

where n is an integer.
- 也就是說,當滿足
時,我們就將相應(yīng)的點放置上去
代碼實現(xiàn)
def Omega2Theta(self):
self.swing()
loop = True
i = 0
n = 0
while(loop):
# omega_D * t = 2 * pi * n
if (self.t[i] > (2*n+1)*math.pi/self.omega_d):
n += 1
if (abs(self.t[i] - 2 * n * math.pi/self.omega_d) < (self.dt/2)):
self.theta_ps.append(self.theta[i])
self.omega_ps.append(self.omega[i])
i += 1
if self.total_time < self.t[i]:
loop = False
接下來讓我們變化一下參數(shù):
我們觀察一下\theta與t在變化的驅(qū)動力下的關(guān)系圖
- 致謝
盧江瑋的代碼助攻~