Classical Harmonic Oscillator

Many problems in physics come down to this simple relation: $$ \ddot{x} = -\omega^2 x $$

where $x$ can be any quantity and $\omega$ can be any combination of relevant constants. The resultant motion is known as "simple harmonic motion", i.e.

$$ x(t) = A \cos(\omega t + \phi) $$

Where $A$ is the amplitude of the motion, $\omega$ is the collection of various constants from before, and $\phi$ is a phase that is set by the initial conditions of the problem.

It is traditional to consider a spring-mass system where a spring with rest length $x_0$ and spring constant $k$ is attached to a mass $m$. If we write down our expression for $\ddot{x}$ using Newton's second law we find $$ m \ddot{x} = -k x $$ which reduces to $$ \ddot{x} = -\omega^2 x $$ where $$ \omega = \sqrt{\frac{k}{m}} $$ We can see that the oscillation frequency of the spring mass system is determined by the stiffness, $k$, of the spring and mass we have attached to it.


In [ ]:
def undamped_oscillator_euler(x0,v0,k,m,tmax,dt):