423 words
2 minutes
Vpython - 雙擺系統完整推導與數值模擬

系統定義#

參數符號說明
上擺質量m1m_1第一個質點質量
下擺質量m2m_2第二個質點質量
上擺長度l1l_1第一段桿長
下擺長度l2l_2第二段桿長
重力加速度gg9.8 m/s²
角度θ1,θ2\theta_1, \theta_2與鉛垂線夾角
角速度ω1,ω2\omega_1, \omega_2θ˙1,θ˙2\dot{\theta}_1, \dot{\theta}_2

質點坐標#

x1=l1sinθ1,y1=l1cosθ1x2=l1sinθ1+l2sinθ2,y2=l1cosθ1l2cosθ2\begin{aligned} x_1 &= l_1 \sin\theta_1, &\quad y_1 &= -l_1 \cos\theta_1 \\ x_2 &= l_1 \sin\theta_1 + l_2 \sin\theta_2, &\quad y_2 &= -l_1 \cos\theta_1 - l_2 \cos\theta_2 \end{aligned}

拉格朗日力學推導#

總動能 T#

T1=12m1l12ω12T2=12m2(l12ω12+l22ω22+2l1l2ω1ω2cos(θ1θ2))T=T1+T2\begin{aligned} T_1 &= \frac{1}{2} m_1 l_1^2 \omega_1^2 \\ T_2 &= \frac{1}{2} m_2 \left( l_1^2 \omega_1^2 + l_2^2 \omega_2^2 + 2 l_1 l_2 \omega_1 \omega_2 \cos(\theta_1 - \theta_2) \right) \\ T &= T_1 + T_2 \end{aligned}

總位能 V#

V=(m1+m2)gl1cosθ1m2gl2cosθ2V = -(m_1 + m_2) g l_1 \cos\theta_1 - m_2 g l_2 \cos\theta_2

拉格朗日量 L#

L=TVL = T - V

運動方程(Euler-Lagrange)#

經過繁瑣推導(相信我你不想手算第二次),得到角加速度:

α1=θ¨1=m2l1ω22sin(θ1θ2)(m1+m2)gsinθ1+m2l2α2cos(θ1θ2)(m1+m2)l1m2l1cos2(θ1θ2) α2=θ¨2=l1ω12sin(θ1θ2)gsinθ2+l1α1cos(θ1θ2)l2\begin{aligned} \alpha_1 = \ddot{\theta}_1 &= \frac{ -m_2 l_1 \omega_2^2 \sin(\theta_1 - \theta_2) - (m_1 + m_2) g \sin\theta_1 + m_2 l_2 \alpha_2 \cos(\theta_1 - \theta_2) }{ (m_1 + m_2) l_1 - m_2 l_1 \cos^2(\theta_1 - \theta_2) } \\\ \alpha_2 = \ddot{\theta}_2 &= \frac{ l_1 \omega_1^2 \sin(\theta_1 - \theta_2) - g \sin\theta_2 + l_1 \alpha_1 \cos(\theta_1 - \theta_2) }{ l_2 } \end{aligned}

(完整推導可見參考資料)

數值積分(Euler 方法)#

每一步更新:

ω1(t+Δt)=ω1(t)+α1Δtω2(t+Δt)=ω2(t)+α2Δtθ1(t+Δt)=θ1(t)+ω1(t+Δt)Δtθ2(t+Δt)=θ2(t)+ω2(t+Δt)Δt\begin{aligned} \omega_1(t + \Delta t) &= \omega_1(t) + \alpha_1 \Delta t \\ \omega_2(t + \Delta t) &= \omega_2(t) + \alpha_2 \Delta t \\ \theta_1(t + \Delta t) &= \theta_1(t) + \omega_1(t + \Delta t) \Delta t \\ \theta_2(t + \Delta t) &= \theta_2(t) + \omega_2(t + \Delta t) \Delta t \end{aligned}

模擬結果展示#

軌跡圖#

雙擺軌跡模擬

流程圖#

模擬流程

能量守恆驗證#

能量守恆圖表

淺藍線為總能量 → 幾乎完全水平,證明數值模擬正確!

參考資料#


Vpython - 雙擺系統完整推導與數值模擬
https://fuwari.vercel.app/posts/物理雙擺模擬/
Author
Guo hua
Published at
2025-03-01
License
CC BY-NC-SA 4.0