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

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

ode = sp.Eq(phi.diff(t, 2) + 4*phi, 0)

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, 10, 400)

phi_vals = phi_sol(t_vals)

plt.figure(figsize=(8, 6))

plt.plot(t_vals, phi_vals, label=r'$\phi(t)$', color='b')

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

plt.xlim(left=0)
plt.ylim(min(phi_vals) - 1, max(phi_vals) + 1)

plt.title(r"Solution of $\frac{d^2\phi}{dt^2} + 4\phi = 0$ with $\phi(0)=3, \frac{d\phi}{dt}(0)=0$")
plt.xlabel('t')
plt.ylabel(r'$\phi(t)$')

plt.grid(True)
plt.legend()

plt.show()