We seek a particular solution of the differential equation
$ x'' + 2p x' + w_0^2 x = G_0 \cos(\omega t)$
and we guess
$ x = a \cos(\omega t) + b \sin(\omega t).$
We plug the guess in, and see what $a$ and $b$ need to be.
# sinusoidally_forced_damped_oscillator
from resources306 import *
from sympy import *
a,b,w,w0,p,t = symbols('a,b,w,w0,p,t',real=True)
G0 = symbols('G0',positive=True)
x = a*cos(w*t) + b*sin(w*t)
#print('The guessed solution:')
#display(x)
de = Eq(diff(x,t,t) + 2*p*diff(x,t) + w0**2*x, G0*cos(w*t) )
dec = de.subs(t,0)
des = de.subs(t,pi/2/w)
print('The two equations to solve for a and b:')
display(dec)
display(des)
sol = solve([dec,des],[a,b])
print('The solution:')
display(sol)
amp = simplify( sqrt(a**2 + b**2).subs(sol) )
print('The amplitude of the solution:')
display( sp.simplify(amp) )
amp = amp.subs({G0:1,w0:1})
from numpy import *
import matplotlib.pyplot as plt
wvals = linspace(0,3,300)
for pval in [2,1,0.5,0.25,0.125,0.0625][::-1]:
ampp = lambdify( w, amp.subs(p,pval), 'numpy' )
plt.plot( wvals, ampp(wvals),label='damping p = '+str(pval) )
plt.legend()
plt.title('amplitude of sinusoidally forced damped oscillator with $G_0=1, \omega_0=1$')
plt.xlabel('forcing frequency, $\omega$')
plt.ylabel('amplitude of response');
The two equations to solve for a and b:
The solution:
The amplitude of the solution: