Harmonic oscillations

The differential equation \[x''+\omega^2x=0 \qquad\text{with}\quad x=x(t)\] rules the harmonic oscillator. This equation gives a good approximation for the motion of a particle attached to a spring or the small oscillations of a simple pendulum. For normalization we consider the initial conditions \(x(0)=0\), \(x'(0)=1\) and the solution is \[x(t)= \omega^{-1}\sin(\omega t).\]

For a fluid like air, in first approximation, the friction is proportional to the velocity (Stokes' law) and then the model equation becomes \[x''+2ax'+\omega^2x=0 \qquad\text{with}\quad a>0.\] This is the damped harmonic oscillator. If the friction is not very large, \(a<\omega\) and the solution is still oscillatory \[x(t)= \widetilde{\omega}^{-1}e^{-at}\sin(\widetilde{\omega}t) \qquad\text{with}\quad \widetilde{\omega}=\sqrt{\omega^2-a^2}.\]

If some periodic external force acts on the oscillator, by Fourier analysis we can restrict ourselves to cosines or cosines with a phase which leads to the equation of the driven harmonic oscillator \[x''+2ax'+\omega^2x=F_e\cos(\omega_e t-\varphi_e).\] Its general solution is \[x(t)=A\cos(\omega t)+B\sin(\omega t) +x_p(t)\] where \(x_p\) is the particular solution \(x_p(t)=C\cos(\omega_e t-\varphi)\) with \[C= \frac{F_e}{\sqrt{(\omega^2-\omega_e^2)^2+4a^2\omega_e^2}} \quad\text{and}\quad \varphi = \arg \Big( \frac{F_e e^{i\varphi_e}}{\omega^2-\omega_e^2-2ia\omega_e} \Big).\] This particular solution is the steady-state solution, the limit when \(t\to +\infty\) of any solution under any initial conditions. Under our initial conditions \[A = -x_p(0) \qquad\text{and}\qquad B = \widetilde{\omega}^{-1}\big(1- x_p'(0)- ax_p(0)\big).\] The denominator in \(C\) measures the gain. If \((\omega^2-\omega_e^2)^2+4a^2\omega_e^2\) is small then \(C>F_e\), the external force is amplified. This requires small friction \(a\) and \(\omega\approx \omega_e\). This is the phenomenon of resonance. If \(a\) is small but not zero, then eventually the solution stabilizes to \(x_p\) which has large amplitude. In the limit case \(a=0\) one obtains an unbounded amplitude given by a linear polynomial. For instance, for \(a=\varphi_e=0\), \(F_e=\omega=\omega_e=1\) the solution under our initial conditions is \(x(t)=(0.5t+1)\sin t\).

Let us see some examples. The figures were made with the code below.

The simplest example is of course the solution of the pure harmonic oscillator:

ho_pure
\(\omega = 2\pi\)

If we introduce a small friction the reduction on the amplitude seems to be linear:

ho_under1
\(\omega = 2\pi\), \(a=0.1\)

But, of course, it is exponential, as shown taking a more noticeable friction:

ho_under2
\(\omega = 2\pi\), \(a=0.5\)

For a driven harmonic oscillator, if \(\omega_e\) is not close to \(\omega\), we observe a "non pure" oscillation with decreasing amplitude according to the friction. In these examples we take \(F_e=1\) and \(\varphi_e= \pi/3\).

ho_driv1
\(\omega = 2\pi\), \(a=0.5\), \(\omega_e = \pi\)

We can see the phenomenon of resonance taking values approaching \(\omega\) and reducing \(a\). In this plot the black, green, blue and red lines correspond to \(\omega_e=\pi\), \(4\pi/3\), \(5\pi/3\) and \(2\pi=\omega\), respectively.

ho_driv2
\(\omega = 2\pi\), \(a=0.01\), \(\omega_e/\omega =\) \(1/2\), \(2/3\), \(5/6\), \(1\)

Taking a higher value of the friction we can notice the convergence to the steady-state solution also in the resonance case.

ho_driv3
\(\omega = \omega_e=2\pi\), \(a=0.3\)





The code

This is the SAGE code that produces all the images:


t = var('t')
tma = 10
thi = 3
fis = 4
fos = 30


def f1(om):
  return sin(om*t)/om


def f2(om, a):
  omp = sqrt( om^2 - a^2 )
  return exp(-a*t)*f1(omp)
  
  
def xp(om, a, ome, Fe, phie):
  phim = CC( Fe*exp(i*phie)/(om^2-ome^2-2*i*a*ome) ).arg()
  C = Fe/sqrt( (om^2-ome^2)^2 +4*a^2*ome^2 )
  x_p = C*cos( ome*t- phim )
  return x_p
  
  
def f3(om, a, ome, Fe, phie):
  omp = sqrt( om^2 - a^2 )
  x_p = xp(om, a, ome, Fe, phie)
  
  A = -x_p(t=0)
  B = -(diff(x_p,t)(t=0) + a*x_p(t=0) -1 )/omp
  
  return A*exp(-a*t)*cos(omp*t) + B*exp(-a*t)*sin(omp*t) + x_p

  
##################################
# PURE HARMONIC OSCILLATOR
om = 2*pi
f = f1(2*pi)
P = plot( f, t, 0, tma, thickness=thi, fontsize =fos)
P.save('../images/ho_pure.png', figsize=[4*fis, fis])


##################################
# UNDERDAMPED HARMONIC OSCILLATOR
om = 2*pi
a = 0.1
f = f2(om, a)
P = plot( f, t, 0, tma, thickness=thi, fontsize =fos)
P.save('../images/ho_under1.png', figsize=[4*fis, fis])

a = 0.5
f = f2(om, a)
P = plot( f, t, 0, tma, thickness=thi, fontsize =fos)
P.save('../images/ho_under2.png', figsize=[4*fis, fis])



##################################
# DRIVEN HARMONIC OSCILLATOR
a = 0.1
ome = pi
Fe = 1
phie = pi/3
f = f3(om, a, ome, Fe, phie)
P = plot( f, t, 0, tma, thickness=thi, fontsize =fos)
P.save('../images/ho_driv1.png', figsize=[4*fis, fis])

a = 0.01
P = point( [(0,0)], size =0)
co = ['black', 'green', 'blue', 'red']
for k in srange(4):
  ome = (1+k/3)*pi
  f = f3(om, a, ome, Fe, phie)
  P += plot( f, t, 0, tma, thickness=thi, fontsize =fos, color = co[k])
P.save('../images/ho_driv2.png', figsize=[4*fis, fis])


ome = 2*pi
a = 0.3
f = f3(om, a, ome, Fe, phie)
P = plot( f, t, 0, tma, thickness=thi, fontsize =fos)
f = xp(om, a, ome, Fe, phie)
P += plot( f, t, 0, tma, thickness=thi, fontsize =fos, color='red')
P.save('../images/ho_driv3.png', figsize=[4*fis, fis])