import sympy as sp
import numpy as np
import matplotlib.pyplot as plt

t = sp.symbols('t')
phi = sp.Function('phi')(t)

p_values = [1, 1.2, 1.4, 1.6, sp.sqrt(3), 2.0]

plt.figure(figsize=(10, 7))

for p in p_values:
    ode = sp.Eq(phi.diff(t, 2) + 1*phi.diff(t) + 4*phi, 2*sp.sin(p*t))
    sol = sp.dsolve(ode, ics={phi.subs(t, 0): 3, phi.diff(t).subs(t, 0): 0})
    phi_sol = sp.lambdify(t, sol.rhs, "numpy")
    t_vals = np.linspace(0, 20, 400)
    phi_vals = phi_sol(t_vals)
    plt.plot(t_vals, phi_vals, label=f'p = {p}')

plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)

plt.title(r"Solutions of $\frac{d^2\phi}{dt^2} + 1\frac{d\phi}{dt} + 4\phi = 2\sin(pt)$")
plt.xlabel('t')
plt.ylabel(r'$\phi(t)$')

plt.grid(True)
plt.legend()

plt.show()