Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Driven Harmonic Oscillator

Source
# IF USING JUPYTER NOTEBOOK:
# %matplotlib notebook
# IF USING JUPYTER LAB:
%matplotlib widget
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.integrate import odeint

Driven Harmonic Oscillator

Author: Ludovic Charleux (ludovic.charleux@univ-smb.fr)

In this example, you will simulate an harmonic oscillator and compare the numerical solution to the closed form one.

Theory

Read about the theory of harmonic oscillators on Wikipedia

Mechanical oscillator

The case of the one dimensional mechanical oscillator leads to the following equation:

mx¨+μx˙+kx=mx¨dm \ddot x + \mu \dot x + k x = m \ddot x_d

Where:

  • xx is the position,

  • x˙\dot x and x¨\ddot x are respectively the speed and acceleration,

  • mm is the mass,

  • μ\mu the

  • kk the stiffness,

  • and x¨d\ddot x_d the driving acceleration which is null if the oscillator is free.

Canonical equation

Most 1D oscilators follow the same canonical equation:

x¨+2ζω0x˙+ω02x=x¨d\ddot x + 2 \zeta \omega_0 \dot x + \omega_0^2 x = \ddot x_d

Where:

  • ω0\omega_0 is the undamped pulsation,

  • ζ\zeta is damping ratio,

  • x¨d=adsin(ωdt)\ddot x_d = a_d\sin(\omega_d t) is the imposed acceleration.

In the case of the mechanical oscillator:

ω0=km\omega_0 = \sqrt{\dfrac{k}{m}}
ζ=μ2mk\zeta = \dfrac{\mu}{2\sqrt{mk}}
omega0 = 2.0 * np.pi * 1.0
zeta = 0.1
ad = 1.0
omegad = 2.0 * np.pi * 1.2

Part 1: Coding

First, you need to code: the harmonic oscillator oscillator using the standarde ODE formulation:

X˙=f(X,t)\dot X = f(X, t)
def f(X, t):
    """
    Driven Harmonic oscillator.
    """
    return

Part 2: Solving

Solve the ODE using odeint and plot it.

Part 3: Steady state amplitude

Determine the steady state amplitude a(ωd)a(\omega_d) of the oscillator.

Part 4: Amplitude vs. drive pulsation

Plot the evolution of the amplitude of the driven oscillator and compare it with the theory.