Q:

Solve $y'+y=|x|, y(-1)=0$. Find y(1)=?

This is my try.
$y(x)e^x=\int|x|e^xdx$
$=\int_x^0(-t)e^tdt+\int_0^xte^tdt$
$=2+2(x-1)e^x+c$
$y(x)=2e^{-x}+(x-1)2+ce^{-x}$.
with $y(-1)=0$ gives $c=1-\frac{3}{e}$
but later I find which is wrong. where is my mistake?

A:

For $x\ge 0$
$$y' + y = x \implies y=c_1 e^{-x}+x-1$$
For $x < 0$
$$y' + y = -x \implies y=c_2e^{-x}-x+1$$
We know that $y(-1)=0$ which implies that
$$0 = c_2e+2 \implies c_2=-\frac{2}{e} = -2e^{-1}$$
We now know that $|x|=|-x|$ at $x=0$ and so
$$-2e^{-1}+1 = c_1 - 1 \implies c_1 = 2-2e^{-1}
$$
$$\color{red}{y =
\begin{cases}
-2e^{-x-1}-x+1,  & \text{if $x$ is negative} \\[2ex]
\;\;\,(2-2e^{-1})e^{-x}+x-1 & \text{if $x$ is non-negative}
\end{cases}}$$

