Coupled Mass-Spring System
Simulate 1–4 coupled masses with springs, damping, and arbitrary forcing \(M\ddot{\mathbf{x}}+C\dot{\mathbf{x}}+K\mathbf{x}=\mathbf{F}(t)\) — observe normal modes, resonance, and beats in real time.
Up to four masses \(m_1,\dots,m_n\) are connected by springs \(k_1,\dots,k_{n+1}\) (each spring \(k_j\) sits to the left of mass \(j\); \(k_{n+1}\) is the right-wall spring). Masses and stiffnesses can all be set independently. The governing system is \(M\ddot{\mathbf{x}}+C\dot{\mathbf{x}}+K\mathbf{x}=\mathbf{F}(t)\) with diagonal mass matrix \(M=\mathrm{diag}(m_1,\dots,m_n)\) and tridiagonal stiffness matrix \[K = \begin{pmatrix} k_1+k_2 & -k_2 & & \\ -k_2 & k_2+k_3 & -k_3 & \\ & -k_3 & \ddots & \ddots \\ & & \ddots & k_{n}+k_{n+1} \end{pmatrix}.\]
Boundary Conditions
The Right end selector switches between a fixed wall on the right (\(k_{n+1}>0\)) and a free right end (\(k_{n+1}=0\)). With a free end the last diagonal entry of \(K\) becomes \(k_n\), giving the classical fixed–free chain with mode frequencies \(\omega_j=2\sqrt{k/m}\,\sin\!\big(\tfrac{(2j-1)\pi}{2(2n+1)}\big)\) and shapes \(u_i^{(j)}=\sin\!\big(\tfrac{(2j-1)i\pi}{2n+1}\big)\). For \(n=4\), uniform \(m=4,\,k=16\), this gives \(\omega_1\!\approx\!0.695,\ \omega_2=2,\ \omega_3\!\approx\!3.06,\ \omega_4\!\approx\!3.76\) rad/s.
Special Forcing Functions
5*delta(t-10).u(t-5)*sin(3*t).Resonance
Resonance occurs when the forcing frequency matches a natural frequency \(\omega_i\) (an eigenvalue of \(M^{-1}K\)). With zero damping, amplitude grows without bound. The default 2-mass example with \(m=4,\ k=16\) (uniform) gives in-phase resonance at \(\omega_1=\sqrt{k/m}=2\) rad/s; non-uniform setups shift the natural frequencies.
Normal Modes (2 Masses, uniform \(m,k\))
- In-phase mode (\(\omega_1=\sqrt{k/m}\)): both masses move together.
- Out-of-phase mode (\(\omega_2=\sqrt{3k/m}\)): masses move in opposite directions.
When \(m_1\neq m_2\) or springs differ, the mode shapes are no longer simply symmetric/antisymmetric — they're the eigenvectors of \(M^{-1}K\), and the heavier mass tends to dominate the slower mode.
Equal initial displacements excite the in-phase mode; opposite displacements excite the out-of-phase mode. Unequal initial conditions produce beats — a periodic exchange of energy between the masses.
Numerical Method
The simulation uses the velocity Verlet (Störmer) integrator — a symplectic method that conserves energy well in undamped cases. Fixed step \(\Delta t=0.01\,\text{s}\).