Example 5. Find the general solution of the equation

$$
y^{\prime \prime}+3 y^{\prime}+2 y=x \sin x
$$
Solution. First method. The characteristic equation $\lambda^{2}+3 \lambda+2=0$ has roots $\lambda_{1}=-1, \lambda_{2}=-2$, therefore

$$
y_{0.0}=C_{1} e^{-x}+C_{2} e^{-2 x}
$$

Since the number $i$ is not a root of the characteristic equation, the particular solution $y_{\text {p.n }}$ of the non-homogeneous equation is sought in the form (see Table 1, case III (1))

$$
y_{\text {p.n }}=\left(A_{1} x+A_{2}\right) \cos x+\left(B_{1} x+B_{2}\right) \sin x,
$$

then

$$
\begin{aligned}
& y_{\text {p.n }}^{\prime}=\left(A_{1}+B_{2}+B_{1} x\right) \cos x+\left(B_{1}-A_{2}-A_{1} x\right) \sin x \\
& y_{4 . n}^{\prime \prime}=\left(2 B_{1} x-A_{2}-A_{1} x\right) \cos x-\left(2 A_{1}+B_{2}+B_{1} x\right) \sin x .
\end{aligned}
$$

Substituting these expressions into the original equation, we get

$$
\begin{aligned}
& \left(2 B_{1}-A_{2}-A_{1} x\right) \cos x-\left(2 A_{1}+B_{2}+B_{1} x\right) \sin x+ \\
& \quad+3\left(A_{1}+B_{2}+B_{1} x\right) \cos x+3\left(B_{1}-A_{2}-A_{1} x\right) \sin x+ \\
& \quad+2\left(A_{1} x+A_{2}\right) \cos x+\left(B_{1} x+B_{2}\right) \sin x=x \sin x
\end{aligned}
$$

or

$$
\begin{aligned}
{\left[\left(A_{1}+3 B_{1}\right) x+3 A_{1}+A_{2}\right.} & \left.+2 B_{1}+3 B_{2}\right] \cos x+ \\
& +\left[\left(\left(-3 A_{1}+B_{1}\right) x-2 A_{1}-3 A_{2}+3 B_{1}+B_{2}\right] \sin x=x \sin x .\right.
\end{aligned}
$$

From this, we obtain a system of linear equations in terms of $A_{1}, A_{2}, B_{1}, B_{2}$

$$
\left\{\begin{aligned}
A_{1}+3 B_{1} & =0 \\
3 A_{1}+A_{2}+2 B_{1}+3 B_{2} & =0 \\
-3 A_{1}+B_{1} & =1 \\
2 A_{1}-3 A_{2}+3 B_{1}+B_{2} & =0
\end{aligned}\right.
$$

Solving this system, we find $A_{1}=-\frac{3}{10}, A_{2}=\frac{17}{50}, B_{1}=\frac{1}{10}, B_{2}=\frac{3}{25}$ and the particular solution $y_{4 . n}$ is written as:

$$
y_{4 \cdot \text {. }}=\left(-\frac{3}{10} x+\frac{17}{50}\right) \cos x+\left(\frac{1}{10} x+\frac{3}{25}\right) \sin x
$$

The general solution of the given equation is

$$
y(x)=C_{1} e^{-x}+C_{2} e^{-2 x}+\left(-\frac{3}{10} x+\frac{17}{50}\right) \cos x+\left(\frac{1}{10} x+\frac{3}{25}\right) \sin x
$$

In the case where the right-hand side $f(x)$ contains trigonometric functions $\sin \beta x$ and $\cos \beta x$, it is convenient to apply the transition to exponential functions. The essence of this method will be shown on an example. Solve the differential equation

$$
y^{\prime \prime}+y=x \cos x
$$

Here $\lambda^{2}+1=0, \lambda_{1}=-i, \lambda_{2}=i$ and the general solution of the homogeneous equation is

$$
y_{0.0}=C_{1} \cos x+C_{2} \sin x
$$

The particular solution of the non-homogeneous equation $y_{\text {p.n }}$ should be sought in the form

$$
y_{4, n}=x\left[\left(A_{1} x+A_{2}\right) \cos x+\left(B_{1} x+B_{2}\right) \sin x\right] .
$$

Let's proceed as follows. Consider the equation

$$
z^{\prime \prime}+z=x e^{i x}
$$

It is easy to see that the right-hand side of the original equation is the real part of the right-hand side of equation (12):

$$
x \cos x=\operatorname{Re}\left(x e^{i x}\right)
$$

Theorem. If a differential equation with real coefficients $L[y]=f_{1}(x)+i f_{2}(x)$ has a solution $y=u(x)+i v(x)$, then $u(x)$ is a solution of the equation $L[y]=f_{1}(x)$, and $v(x)$ is a solution of the equation $L[y]=f_{2}(x)$.

Let's find $z_{1 ., 4}$ of equation (12):

$$
\begin{aligned}
& z_{\text {p.n }}=(A x+B) x e^{i x}=\left(A x^{2}+B x\right) e^{i x} \\
& z_{p, n}^{\prime \prime}=2 A e^{i x}+2(2 A x+B) i e^{i x}-\left(A x^{2}+B x\right) e^{i x} .
\end{aligned}
$$

Substituting into equation (12) and canceling both sides by $e^{i x}$, we get

$$
2 A+4 A x i+2 B i=x
$$

from which $4 A i=1, A=-\frac{i}{4}, A+B i=0, B=-\frac{A}{i}=\frac{1}{4}$, so

$$
\begin{aligned}
z_{\text {p.n }}=\left(-\frac{i}{4} x^{2}+\frac{1}{4} x\right) e^{i x}=\left(-\frac{i}{4} x^{2}\right. & \left.+\frac{1}{4} x\right)(\cos x+i \sin x)= \\
& =\frac{x \cos x+x^{2} \sin x}{4}+i \frac{x \sin x-x^{2} \cos x}{4}
\end{aligned}
$$

From this, by the theorem,

$$
y_{4, n}=\operatorname{Re} z_{p, n}=\frac{x \cos x+x^{2} \sin x}{4}
$$

This method sometimes significantly simplifies and shortens the calculations related to finding particular solutions.

Solution of Example 5. Second method. Let's solve this example by transitioning to exponential functions. Consider the equation

$$
z^{\prime \prime}+3 z^{\prime}+2 z=x e^{i x} .
$$

It is easy to see that the right-hand side of the original equation is the imaginary part of $x e^{i x}$:

$$
x \sin x=\operatorname{Im}\left(x e^{i x}\right)
$$

We seek $z_{\text {p.n }}$ of equation (13) in the form

$$
z_{p, n}=(A x+B) e^{i x}
$$

then

$$
z_{4,11}^{\prime}=A e^{i x}+i(A x+B) e^{i x}, \quad z_{4,11}^{\prime \prime}=2 i A e^{i x}-(A x+B) e^{i x}
$$

Substituting these expressions into (13) and canceling by $e^{i x}$, we get

$$
2 A i-A x-B+3 A+3 A i x+3 B i+2 A x+2 B=x
$$

from which

$$
\left\{\begin{aligned}
A+3 A i & =1 \\
2 A i+B+3 A+3 B i & =0
\end{aligned}\right.
$$

so

$$
A=\frac{1}{1+3 i}=\frac{1}{10}-\frac{3 i}{10}, \quad B=-\frac{A(3+2 i)}{1+3 i}=\frac{6}{50}+\frac{17}{50} i
$$

Thus,

$$
\begin{aligned}
& z_{1.11}=\left(\frac{1-3 i}{10} x+\frac{6+17 i}{50}\right) e^{i x}=\left(\frac{5 x+6}{50}+\frac{17-15 x}{50} i\right) \times \\
& \times(\cos x+i \sin x)=\frac{(5 x+6) \cos x+(15 x-17) \sin x}{50}+ \\
&+i \frac{(5 x+6) \sin x+(17-15 x) \cos x}{50}
\end{aligned}
$$

from which

$$
y_{\text {p.n }}=\operatorname{Im} z_{\text {p.n }}=\frac{5 x+6}{50} \sin x+\frac{17-15 x}{50} \cos x
$$

which coincides with $y_{\text {p.n }}$ found earlier.