Show code cell 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:
Where:
is the position, and are respectively the speed and acceleration, is the mass, the the stiffness,and
the driving acceleration which is null if the oscillator is free.
Canonical equation#
Most 1D oscilators follow the same canonical equation:
Where:
is the undamped pulsation, is damping ratio, is the imposed acceleration.
In the case of the mechanical oscillator:
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:
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
Part 4: Amplitude vs. drive pulsation#
Plot the evolution of the amplitude of the driven oscillator and compare it with the theory.