# How to solve $y''+4y=e^x\cos2x+3e^{3x}$?

I use undetermined coefficient method to find that the solution is

$y=y_h+y_p$

$y_h=C_1\cos2x+C_2\sin2x$

$y_p=\frac{1}{17}e^x\cos2x+\frac{4}{17}e^x\sin2x+\frac{3}{13}e^{3x}$

therefore,$$y=C_1\cos2x+C_2\cos2x+\frac{1}{17}e^x\cos2x+\frac{4}{17}e^x\sin2x+\frac{3}{13}e^{3x}$$

However,I see the solution in my book and I don't quite understanding its method

It separates the R.H.S into 2 parts

Let $y_p=Ae^x\cos2x+Be^x\sin2x$ first

$$\begin{pmatrix}1 &4 \\ -4 &1 \end{pmatrix} \begin{pmatrix}A\\ B\end{pmatrix} = \begin{pmatrix}1\\ 0\end{pmatrix}$$

$A=\frac{1}{17},B=\frac{4}{17}$

Then,

Let $y_{p2}=Ce^{3x}$

$(3^2+4)C=3$

$C=\frac{3}{13}$

How can I to do it in this way?

You can do that with every linear ODE. If $L(y)=0$ is the homogeneous equation, with $L$ as the differential operator, here $L=\frac{d^2}{dx^2}+4$, and you have particular solutions for each of the terms in the sum on the right side, $L(y_{p1})=f_1$, $L(y_{p2})=f_2$, …, $L(y_{pk})=f_k$, then by linearity you can assemble a particular solution for the full sum on the right side as $$L(y_{p1}+y_{p2}+…+y_{pk})=f_1+f_2+…+f_k.$$