This is an old version, view current version.

13.1 Example: Simple Harmonic Oscillator

As an example of a system of ODEs, consider a harmonic oscillator, which is characterized by an equilibrium position and a restoring force proportional to the displacement with friction. The system state will be a pair \(y = (y_1, y_2)\) representing position and momentum: a point in phase space. The change in the system with respect to time is given by the following differential equations.24

\[ \frac{d}{dt} y_1 = y_2 \ \ \ \ \ \ \ \ \ \ \ \frac{d}{dt} y_2 = -y_1 - \theta y_2 \] id:ode-sho.equation

The state equations implicitly define the system state at a given time as a function of an initial state, elapsed time since the initial state, and the system parameters.

Solutions Given Initial Conditions

Given a value of the system parameter \(\theta\) and an initial state \(y(t_0)\) at time \(t_0\), it is possible to simulate the evolution of the solution numerically in order to calculate \(y(t)\) for a specified sequence of times \(t_0 < t_1 < t_2 < \cdots\).


  1. This example is drawn from the documentation for the Boost Numeric Odeint library (Ahnert and Mulansky 2011), which Stan uses to implement the rk45 solver.↩︎