In this case we solve the differential equation $y' + 3y = \sin{x} + \cos{x}$. Note the extensive usage of complex numbers.

\[\begin{aligned}

y' + 3y &= \sin{x} + \cos{x}\\

e^{3x} \cdot y' + 3 e^{3x} \cdot y &= e^{3x}(\sin{x} + \cos{x}) \\

(e^{3x} \cdot y)' &= e^{3x}(\sin{x} + \cos{x})\\

(e^{3x} \cdot y)' &= e^{3x}\sqrt{2}\cos{(x-\frac{\pi}{4})}\\

(e^{3x} \cdot y)' &= \Re{\left\{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x}\right\}}\\

\int{(e^{3x} \cdot y)' \ dx} &= \Re{\left\{ \int{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x} \ dx}\right\}}\\

\int{(e^{3x} \cdot y)' \ dx} &= \Re{\left\{ \int{ \sqrt{2} e^{(3+i)x-\frac{\pi}{4}i} \ dx}\right\}}\\

e^{3x} \cdot y &= \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(3+i)x-\frac{\pi}{4}i} \right\}} + C\\

y &= \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(x-\frac{\pi}{4})i} \right\}} + Ce^{-3x}\\

y &= \frac{1}{5}\cos{x} + \frac{2}{5}\sin{x} + Ce^{-3x}

\end{aligned} \]

Step 1:

$y' + 3y = \sin{x} + \cos{x} \Leftrightarrow$

$e^{3x} \cdot y' + 3 e^{3x} \cdot y = e^{3x}(\sin{x} + \cos{x}) $

We want to multiply the LHS and RHS with a factor $p(x)$ such that $p(x) \cdot y + 3 p(x) \cdot y' = (y\cdot p(x))'$. This implies that $p'(x) = 3p(x) \Leftrightarrow p(x) = \int{3p(x) \ dx} \Leftrightarrow p(x) = e^{3x} + C$. For our purpose $C=0$ suffices.

Step 2:

$e^{3x} \cdot y' + 3 e^{3x} \cdot y = e^{3x}(\sin{x} + \cos{x}) \Leftrightarrow$

$(e^{3x} \cdot y)' = e^{3x}(\sin{x} + \cos{x})$

We implement our objective from the previous step. This step is allowed due to the product rule of differentiation: $(f\cdot g)'(x) = f(x)g'(x) + g(x)f'(x)$.

Step 3:

$(e^{3x} \cdot y)' = e^{3x}(\sin{x} + \cos{x}) \Leftrightarrow$

$(e^{3x} \cdot y)' = e^{3x}\sqrt{2}\cos{(x-\frac{\pi}{4})}$

We want the RHS to be a single trigonometric function:

\[\begin{aligned}

\cos{x}+\sin{x} &= \Re{(e^{ix})} + \Re{(-ie^{ix})}\\

&=\Re{(e^{ix}-ie^{ix})}\\

&=\Re{((1-i)e^{ix})}\\

&=\Re{(\sqrt{2}e^{-\frac{\pi}{4}i} \cdot e^{ix})}\\

&=\Re{(\sqrt{2}e^{(x-\frac{\pi}{4})i})}\\

&=\Re{(\sqrt{2}(\cos{(x-\frac{\pi}{4})}+i\sin{(x-\frac{\pi}{4})}))}\\

&=\sqrt{2}\cos{(x-\frac{\pi}{4})}

\end{aligned} \]

Step 4:

$(e^{3x} \cdot y)' = e^{3x}\sqrt{2}\cos{(x-\frac{\pi}{4})} \Leftrightarrow$

$(e^{3x} \cdot y)' = \Re{\left\{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x}\right\}}$

If we write the RHS again as the real part of a complex expression we can integrate a single exponential function which is preferable due to its simplicity.

Step 5:

$(e^{3x} \cdot y)' = \Re{\left\{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x}\right\}} \Leftrightarrow$

$\int{(e^{3x} \cdot y)' \ dx} = \Re{\left\{ \int{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x} \ dx}\right\}}$

An intermediate step before integration, the RHS needs tyding up in the next step before integration over x.

Step 6:

$\int{(e^{3x} \cdot y)' \ dx} = \Re{\left\{ \int{ \sqrt{2} e^{(x-\frac{\pi}{4})i+3x} \ dx}\right\}} \Leftrightarrow$

$\int{(e^{3x} \cdot y)' \ dx} = \Re{\left\{ \int{ \sqrt{2} e^{(3+i)x-\frac{\pi}{4}i} \ dx}\right\}}$

In this step we have rewritten the RHS so that it is clear how the integration has to be done.

Step 7:

$\int{(e^{3x} \cdot y)' \ dx} = \Re{\left\{ \int{ \sqrt{2} e^{(3+i)x-\frac{\pi}{4}i} \ dx}\right\}} \Leftrightarrow$

$e^{3x} \cdot y = \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(3+i)x-\frac{\pi}{4}i} \right\}} + C$

In this step we have performed a straightforward integration of the LHS and RHS.

Step 8:

$e^{3x} \cdot y = \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(3+i)x-\frac{\pi}{4}i} \right\}} + C \Leftrightarrow$

$y = \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(x-\frac{\pi}{4})i} \right\}} + Ce^{-3x}$

We divide LHS and RHS by $e^{3x}$.

Step 9:

$y = \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(x-\frac{\pi}{4})i} \right\}} + Ce^{-3x} \Leftrightarrow$

$y = \frac{2}{5}\sin{x} + \frac{1}{5}\cos{x} + Ce^{-3x}$

We rearrange the RHS as follows:

\[\begin{aligned}

y

&= \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(x-\frac{\pi}{4})i} \right\}} + Ce^{-3x}\\

&= \Re{\left\{ \frac{\sqrt{2}}{3+i} e^{(x-\frac{\pi}{4})i} \right\}} + Ce^{-3x} \\

&= \Re{\left\{ \frac{1}{3+i} \frac{3-i}{3-i}(1-i)e^x \right\}} + Ce^{-3x} \\

&= \Re{\left\{ (\frac{1}{5}-\frac{2}{5}i)(\cos{x}+i\sin{x}) \right\}} + Ce^{-3x} \\

&= \Re{\left\{ \frac{1}{5}\cos{x} + \frac{2}{5}\sin{x} +i(-\frac{2}{5}\cos{x} + \frac{1}{5}\sin{x}) \right\}} + Ce^{-3x} \\

&= \frac{1}{5}\cos{x} + \frac{2}{5}\sin{x} + Ce^{-3x}

\end{aligned} \]

This completes the explanation.