The question:

$\displaystyle y'' - y = e^{-x}$

My attempt:

Finding homogeneous solution:

$\displaystyle \lambda^2 - 1 = 0$

$\displaystyle \lambda = 1, -1$

So we have $\displaystyle y = Ae^x + Be^{-x}$

Finding a particular solution, I tried $\displaystyle y = Ce^{ax}$, but noticed that this is also a solution to the homogeneous equation. So instead, I went with $\displaystyle y = Cxe^{ax}$.

Finding derivatives:

$\displaystyle y' = Caxe^{ax} + Ce^{ax}$

$\displaystyle y'' = Ca^2xe^{ax} + 2Cae^{ax}$

Substituting into the ODE:

$\displaystyle Ca^2xe^{ax} + 2Cae^{ax} - Cxe^{ax} = e^{-x}$

$\displaystyle Ca^2xe^{ax} + Cxe^{ax} = e^{-x}$

Clearly a = -1, so:

$\displaystyle Cxe^{-x} + Cxe^{-x} = e^{-x}$

$\displaystyle 2Cxe^{-x} = e^{-x}$

So we want $\displaystyle 2Cx = 1$

$\displaystyle C =\frac{1}{2x}$

Substituting into the general solution:

$\displaystyle y = \frac{1}{2x}xe^{-x}$

$\displaystyle y = \frac{1}{2}e^{-x}$

Adding homogeneous and particular solutions:

$\displaystyle y = Ae^x + Be^{-x} + \frac{1}{2}e^{-x}$

$\displaystyle y = e^{-x}(B + \frac{1}{2}) + Ae^x$

However, the solution is:

$\displaystyle y = (A - \frac{x}{2})e^{-x} + Be^x$

I'm not sure where that x came from. I'm sure I'm missing something obvious here. Any help would be great!