Problem: Solve the differential equation
\[
\frac{\mathrm{d}^2y}{\mathrm{d}x^2} + y = \cos 2x .
\]
Solution: We want to solve the differential equation
\begin{equation}\label{eq:21June2024-1}
\frac{\mathrm{d}^2y}{\mathrm{d}x^2} + y = \cos 2x.
\end{equation}
The corresponding homogeneous equation is $\frac{\mathrm{d}^2y}{\mathrm{d}x^2} + y =0$ and hence the auxiliary equation will be
\[
m^2 + 1 = 0 \implies m = \pm \iota .
\]
Therefore, the solution corresponding to the homogeneous equation of \eqref{eq:21June2024-1} will be
\begin{equation}\label{eq:21June2024-2}
y_{\mathsf{cf} } = c_1 \cos x + c_2 \sin x.
\end{equation}
Now we can find the particular integral by using the method of
variation of parameters. Take
\begin{equation}\label{eq:21June2024-3}
y_{\mathsf{PI}} = A \cos 2x + B \sin 2x .
\end{equation}
Substituting \eqref{eq:21June2024-3} in \eqref{eq:21June2024-1}, we obtain
\begin{align*}
& -4 A \cos 2x - 4B \sin 2x + A \cos 2x + B \sin 2x = \cos 2x \\
\implies & -3A \cos 2x -3B \sin 2x = \cos 2x \\
\implies & -3A = 1 \text{ and } -4B = 0 \\
\implies & A = -\frac{1}{3} \text{ and } B = 0.
\end{align*}
Thus,
\[
y_{\mathsf{PI} } = -\frac{1}{3} \cos 2x .
\]
Therefore, the solution to the given differential equation will be
\[
y(x) = c_1 \cos x + c_2 \sin x - \frac{\cos 2x}{3}.
\]