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=(y1,y2) 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

ddty1=y2ddty2=y1θy2

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 θ and an initial state y(t0) at time t0, it is possible to simulate the evolution of the solution numerically in order to calculate y(t) for a specified sequence of times t0<t1<t2<.


  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.↩︎