To solve $ y'+y=|x|$ 
What is the solution to the IVP $$y'+y=|x|, \ x \in \mathbb{R}, \ y(-1)=0$$

The general solution of the above problem is $y_{g}(x)=ce^{-x}$.
How to find the particular solution? As $|x|$ is not differentiable at origin. Is there any alternate way to get the solution?
 A: Hint: using the integrating factor the equation can be rewritten as
$$
(e^{x}y(x))'=e^{x}|x|.
$$
Thus, you are left with writing down the solution to $w'(x)=f(x)$, $w(x_0)=0$ ($f$ continuous).

 $$w(x)=\int_{x_0}^x f(t)\,dt.$$

A: or use the variation of parameters method
$$y=y_c+y_p$$
we know that $y_c=ce^{-x}$
so
$$y_p=u(x)e^{-x}$$
$$y'_p=u'(x)e^{-x}-u(x)e^{-x}$$
substitute in the D.E to get
$$u(x)=\int|x|e^{x}dx=e^x(x-1)\operatorname{sgn}(x)+\operatorname{sgn}(x)+1$$
so the
$$y_p=(x-1)\operatorname{sgn}(x)+e^{-x}[\operatorname{sgn}(x)+1]$$
A: You have to distinguish the two cases whether $x < 0$ and $x \geq 0$ and see that the two solutions "matches" at the origin.
When $x < 0$, $y'+y=-x$ you look for a particular solution of the form $y_p(x)=ax+b$ and gives you $a+ax+b=-x$, therefore $a=-1$ and $b=-a=1$ so $y_p(x)=-x+1$
When $x \geq 0$, $y'+y=x$ you look for a particular solution of the form $y_p(x)=ax+b$ and gives you $a+ax+b=x$, therefore $a=1$ and $b=-a=-1$ so $y_p(x)=x-1$
So now we have $y(x)=c_1e^{-x}-x+1$ for $x < 0$ and $y(x)=c_2e^{-x}+x-1$ for $x \geq 0$
The initial condition $y(-1)=0$ gives us $0=c_1e+1+1$ i.e. $c_1=-2e^{-1}$ and we get $y(x)=-2e^{-x-1}-x+1$ for $x < 0$.
Now we want our two solutions to match at the origin so $-2e^{-1}+1=c_2-1$, so $c_2=2(1-e^{-1})$ and we get $y(x)=2(1-e^{-1})e^{-x}+x-1$ when $x \geq 0$
Finally we can write our solution $$y(x)=-2e^{-x+1}-x+1 \ \mathrm{when\ } x < 0$$
$$y(x)=2(1-e^{-1})e^{-x}+x-1 \ \mathrm{when \ }x \geq 0 $$
A: To find a particular solution, you can explore the Ansatz
$$y=|x|,$$ giving $$y'+y=\text{sgn}(x)+|x|.$$
This is valid on the whole real line, except at the origin, where the discontinuity is unavoidable. So compensating the sign term, there is a piecewise solution,
$$y=|x|-\text{sgn}(x).$$
The rest is standard.

 $$x<0\to y=-\dfrac2ee^{-x}-x+1,\\x>0\to y=ce^{-x}+x-1$$ where $c$ is unknown.

A: $$y'+y=|x|$$
Solving without condition :
Case $x>0 \quad:\quad y'+y=x \qquad y=c_1e^{-x}+x-1$
Case $x<0 \quad:\quad y'+y=-x \qquad y=c_2e^{-x}-x+1$
$$y=ce^{-x}+(x-1)\text{ sgn}(x)$$
sgn$(x)$ is the function sign of $x$
The function is discontinuous at $x=0$.

The discontinuous curve represented is only an example for a particular value of $c_1=c_2=c$. Of course they are an infinity of solutions. Don't confuse this general equation with the solution below which is strictly the answer corresponding to the condition $y(-1)=0$.
With condition $\quad y(-1)=0$ :
$y(-1)=0=c_2e^{-(-1)}+((-1)-1)(-1)=c_2e+2\quad;\quad c_2=-\frac{2}{e}$
$$y=-2e^{-x-1}-x+1 \quad \text{in } x\leq 0. \tag 1$$
In $x>0$ :
Condition $y(0)=1-2e^{-1}$
$y(0)=1-2e^{-1}=c_1e^{-0}+0-1=c_1-1\quad;\quad c_1=2-2e^{-1}$
$$y=2(1-e^{-1})e^{-x}+x-1 \quad \text{in } x\geq 0. \tag 2$$

Note after the comments :
The above solution Eqs.$(1)$ and $(2)$ is the same as the LutzL's solution written on a different form :
$$y=ce^{-x}+sign(e^{-x}-1+x)$$
with $c=1+2e^{-1}$.
