Example 3. Integrate the linear equation $y^{\prime}+y=x+2$.
Solution. Let $y=u v$, then

$$
y^{\prime}=u^{\prime} v+u v^{\prime}
$$

Substituting the expressions for $y$ and $y^{\prime}$ into the equation, we get

$$
u^{\prime} v+u v^{\prime}+u v=x+2, u\left(v^{\prime}+v\right)=x+2-u^{\prime} v
$$

Require that $v^{\prime}+v=0$, then

$$
\frac{d v}{d x}+v=0, \frac{d v}{v}=-d x, \ln v=-x, v=e^{-x}
$$

If $v^{\prime}+v=0$, then equation (A) becomes

$$
x+2-u^{\prime} v=0
$$

Substituting the value of $v$ here, rewrite the equation as

$$
x+2-e^{-x} \frac{d u}{d x}=0, d u=e^{x}(x+2) d x
$$

Integrating the last equation, we get

$$
\begin{gathered}
u=\int e^{x}(x+2) d x=\int x e^{x} d x+2 \int e^{x} d x=x e^{x}-\int e^{x} d x+2 e^{x}+C \\
u=x e^{x}+e^{x}+C
\end{gathered}
$$

Therefore,

$$
y=u v=e^{-x}\left[C+e^{x}(x+1)\right] .
$$

Thus, the general solution is given by the formula

$$
y=C e^{-x}+x+1
$$