Example 4.23. Find the general solution of the equation

$$
y^{\prime \prime}-4 y^{\prime}+5 y=2 \cos x+6 \sin x
$$
Solution. 1. Find $\bar{y}$. The characteristic equation

$$
r^{2}-4 r+5=0
$$

has roots $r_{1,2}=2 \pm i$. Therefore,

$$
\bar{y}=e^{2 x}\left(C_{1} \cos x+C_{2} \sin x\right)
$$

2. We will now find $y^{*}$. Here the right-hand side $f(x)$ has the form (4): $a=2, b=6, \lambda= \pm i$. The numbers $\pm i$ are not roots of the characteristic equation, so the particular solution $y^{*}$ should be sought in the form

$$
y^{*}=A \cos x+B \sin x,
$$

where $A$ and $B$ are undetermined coefficients. We find the derivatives $y^{*^{\prime}}$ and $y^{* \prime \prime}:$

$$
\begin{aligned}
& y^{*}=-A \sin x+B \cos x \\
& y^{*}=-A \cos x-B \sin x
\end{aligned}
$$

Substituting now the expressions for $y^{*}, y^{* \prime}$, and $y^{* \prime \prime}$ into the given equation and grouping the terms involving $\cos x$ and $\sin x$, we obtain

$$
(4 A-4 B) \cos x+(4 A+4 B) \sin x=2 \cos x+6 \sin x
$$

Therefore, to find $A$ and $B$ we have the system

$$
\begin{aligned}
& 4 A-4 B=2 \\
& 4 A+4 B=6
\end{aligned}
$$

from which $A=1, B=\frac{1}{2}$. Thus,

$$
y^{*}=\cos x+\frac{1}{2} \sin x
$$

Therefore, the general solution of the given equation is:

$$
y=\bar{y}+y^{*}=e^{2 x}\left(C_{1} \cos x+C_{2} \sin x\right)+\cos x+\frac{1}{2} \sin x
$$