1. Second order non-homogeneous ODE

The question:
$y'' - y = e^{-x}$

My attempt:
Finding homogeneous solution:
$\lambda^2 - 1 = 0$
$\lambda = 1, -1$

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

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

Finding derivatives:

$y' = Caxe^{ax} + Ce^{ax}$
$y'' = Ca^2xe^{ax} + 2Cae^{ax}$

Substituting into the ODE:

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

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

Clearly a = -1, so:

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

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

So we want $2Cx = 1$

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

Substituting into the general solution:
$y = \frac{1}{2x}xe^{-x}$

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

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

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

However, the solution is:

$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!

2. Your particular solution has too many constants. You can try $\displaystyle y = Cx\,e^{-x}$.

3. Ahh, thank you. I'll try that after I have some dinner. :P