import numpy as np
from numpy import exp
from cmath import sqrt
import sympy as sp
import matplotlib.pyplot as plt
%matplotlib inline
t = np.linspace(0,1,100)
omega0 = 10
Q = 0.3
gamma = omega0/Q
omegav = omega0 * sqrt(1 - 1/(4*Q**2))
A = 1.0
phi = 0
def z(gamma, A, omegav, phi):
return A * np.exp(-gamma/2*t) * np.exp(1j*(omegav*t + phi))
for Q in [0.2,0.3,0.4, 0.5, 0.6, 0.7, 1]:
gamma = omega0/Q
omegav = omega0 * sqrt(1 - 1/(4*Q**2))
phi = 0
A = 1.0
plt.plot(t,np.real(z(gamma, A, omegav, phi)) ,label=Q)
plt.legend()
<matplotlib.legend.Legend at 0x11bd48860>
Trying a numerical approach.
from scipy.integrate import odeint
def sho(y, t, gamma, w2):
x, xdot = y
dydt = [xdot, -gamma*xdot - w2*x]
return dydt
gamma = 6
w2 = 9
y0 = [np.pi/2, 0.0]
t = np.linspace(0,10,100)
sol = odeint(sho, y0, t, args=(gamma,w2))
plt.plot(t, sol[:,0], ".-", label='x(t)')
[<matplotlib.lines.Line2D at 0x151eac97b8>]
odeint?