mathematics//differential equations//ODE//oscillator
The oscillator is the typical second-order equation, and it still lives in a two-dimensional state space. Its mechanical form, a mass \(m\) on a spring \(k\) with a damper \(c\) under a force \(F\), \(m\ddot p+c\dot p+kp=F\), is the canonical second-order mechanical system: a car's suspension, a sensor's proof mass, a machine on its mounts. Written abstractly,
The oscillator is the typical second-order equation, and it still lives in a two-dimensional state space. Its mechanical form, a mass mmm on a spring kkk with a damper ccc under a force FFF, mp¨+cp˙+kp=Fm\ddot p+c\dot p+kp=Fmp¨+cp˙+kp=F, is the canonical second-order mechanical system: a car's suspension, a sensor's proof mass, a machine on its mounts. Written abstractly,
r˙=Aj,j˙=−Br⟹r¨+ABr=0.\dot r=Aj,\qquad \dot j=-Br\quad\Longrightarrow\quad \ddot r+ABr=0.r˙=Aj,j˙=−Br⟹r¨+ABr=0.
Differentiate the first equation and substitute the second and the pair of first-order equations becomes one second-order equation. Read backwards, that is how a second-order equation is always turned into a first-order system: name the velocity as a state.
An acceleration is involved, but the acceleration is a function of the position, so it is not a new dimension. The state is (r,j)(r,j)(r,j), the plane is two-dimensional, and the trajectories are closed curves around the origin turning at angular frequency AB\sqrt{AB}AB. Drawn in one quadrant, an arrow at (r,j)(r,j)(r,j) points with components (Aj,−Br)(Aj,-Br)(Aj,−Br): the arrows are the dotted variables, the axes are the plain ones (phase portrait).
The same equation with damping, r¨+cr˙+ABr=0\ddot r+c\dot r+ABr=0r¨+cr˙+ABr=0, spirals inward instead of circling; in the language of modes the undamped case has a purely imaginary pair of eigenvalues and the damped one a pair with negative real part.
Two initial data are needed, r(0)r(0)r(0) and j(0)j(0)j(0), one per state (initial condition); the energy-like quantity Br2+Aj2Br^2+Aj^2Br2+Aj2 is conserved by the undamped field, a constraint that appears from the equations rather than being imposed.
The mass-spring-damper analogy reaches far beyond springs. A PD controller acting on a mass pushes back in proportion to the error, like a spring of stiffness KpK_pKp, and in proportion to the velocity, like a damper KdK_dKd, so the controlled double integrator obeys exactly this equation; tuning the gains is choosing a stiffness and a damping (second-order system).
It is the standard trap for simulators. An explicit Euler step multiplies each oscillation by ∣1+jωΔt∣>1|1+j\omega\Delta t|>1∣1+jωΔt∣>1, so the simulated oscillator gains energy at every step whatever the step size, while the semi-implicit variant (update the velocity first, then the position with the new velocity) costs the same and keeps the energy bounded (Euler method).