I'll make it brief.
I need to solve the equation: $$ y'' + y = 5xe^{2x} $$
which should yield the result: $$ y = A\cos x + B\sin x + xe^{2x} - \frac{4}{5}e^{2x} $$
I almost get the correct solution apart from the last negative term, and I have no idea where it comes from. I know that the C.F. has to be $A\cos x + B\sin x$, and I tried a P.I. of $y = \lambda x e^{kx}$ and when comparing coefficients after reinserting $y$ and $y''$, I am left with: $$ e^{kx}(k^2\lambda x + 2k\lambda + \lambda x) = 5xe^{kx} $$
As a result, I correctly acquired that $k = 2$, but I am left with: $$ 5 \lambda x + 4 \lambda = 5x $$
which leads me to nonsense.
Can anyone care to help me and tell me where I went wrong? Much appreciated.
I have a feeling this is one of those situations where I'll slap my forehead once I realise what I did wrong.
When your forcing function is a polynomial ($x$) times another function whose derivative keeps its form ($e^{2x}$), your guess for the particular solution should be that function times an arbitrary polynomial of the same degree (or higher, if the function appears in the homogeneous solution). In particular, note that even if some of the coefficients for the forcing function polynomial are 0 (like the $x^0$ term), the particular solution should still have an arbitrary coefficient. For your case, you should try $y_p(x)=(\lambda x+\gamma)e^{2x}$.
From there, you should be able to plug in and evaluate the derivatives to solve for $\lambda$ and $\gamma$.