In [53]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

import seaborn as sns

def x_xdot(A, omega):

    t = np.arange(-2*np.pi, 2*np.pi, .01)

    x = A * np.sin(omega*t)
    xdot = A * omega * np.cos(omega*t)

    return [x, xdot]

omega = .5
plt.figure(figsize=(8.5, 6))
for A in [1, 2, 3]:
     plt.plot(*x_xdot(A, omega), label='A={}'.format(A))
        
plt.legend()
plt.xlim([-4, 4])
plt.ylim([-2, 2])
plt.xlabel('$x$', fontsize=20)
plt.ylabel('$\dot{x}$', fontsize=20)
plt.title('Simple harmonic oscillator phase diagrams ($\omega_0 = 0.5$)')


Out[53]:
<matplotlib.text.Text at 0x10f2d06a0>

In [54]:
t = np.arange(-8*np.pi, 8*np.pi, .01)


def omega(omega_0, beta):
    return np.sqrt(omega_0**2 - beta**2)


def x_damped(A, omega_0, beta):

    omega_1 = omega(omega_0, beta)
    
    return A * np.exp(-beta * t) * np.cos(omega_1*t)


def xdot_underdamped(A, omega_0, beta):

    omega_1 = omega(omega_0, beta)
    
    return -A*np.exp(-beta * t) * \
        (beta*np.cos(omega_1 * t) + omega_1*np.sin(omega_1 * t))

A = 1.0
omega_0 = 0.5
plt.figure(figsize=(8.5, 6))
for beta in [0.1, 0.2, 0.4]:
    plt.plot(x_damped(A, omega_0, beta), xdot_underdamped(A, omega_0, beta),
             label='$\\beta={}$'.format(beta)
             )
    
plt.legend()
plt.xlabel('$x$', fontsize=20)
plt.ylabel('$\dot{x}$', fontsize=20)
plt.xlim([-8, 8])
plt.ylim([-8, 8])
plt.title('Underdamped harmonic oscillator phase diagrams ($A=1.0$ and $\omega_0 = 0.5$)')


Out[54]:
<matplotlib.text.Text at 0x10f4da198>