ODE problem, now a days asked quite frequently (inhomogeneous) How to solve 
$$\frac {ds}{dt}+s=|t|,~s(0)=1.$$ 
Because i have never seen before such a inhomogeneous ODE, where on right hand side there is modulus function. What i did to solve it, i broken up right hand side in to two point function by definition of modulus function, but still i did not get my apple. Any help will be appreciated. Thank you
 A: Solution in $\mathbb{R}$: You can solve the ODE in $2$ domains: $t\leqslant0$ and $t\geqslant0$. For each domain you can get a set of solutions with $1$ degree of freedom and then you can find the overall solution by joining the two together with the known border condition ($s$ continuous at $0$ and $s(0) = 1$).
Details:
Solving $\frac{\mathrm{d}s}{\mathrm{d}t} + s = t, \quad t \geqslant 0$, you get the set of solutions :
$$ S_1 = \{t \mapsto t - 1 + c_1 e^{-t} \,;\, c_1 \in \mathbb{R} \}. $$
Solving $\frac{\mathrm{d}s}{\mathrm{d}t} + s = -t, \quad t \leqslant 0$, you get the set of solutions :
$$ S_2 = \{t \mapsto 1 - t + c_2 e^{-t} \,;\, c_2 \in \mathbb{R} \}. $$
So the overall solution should have the form:
$$ s(t) = \begin{cases} t - 1 + c_1 e^{-t}, & \forall t \geqslant 0 \\ 1 - t + c_2 e^{-t}, & \forall t \leqslant 0\end{cases}$$
At $t = 0$, we should have $\lim_{t\to 0^-}s(t) = \lim_{t\to 0^+}s(t)$ and $s(0) = 1$, thus 
$$ c_1 = 2, \quad c_2 = 0. $$
The overall solution is:
$$ s(t) = \begin{cases} t - 1 + 2 e^{-t}, & \forall t \geqslant 0 \\ 1 - t , & \forall t < 0\end{cases}$$
A: You can use the standard method of solving a linear ODE. First multiply by $e^{t}$: $$\frac{ds}{dt} e^t + s e^{t} = e^{t} |t|$$ then we have $$\frac{d}{dt}( e^t s(t) ) = e^t |t|$$
Then we have $$\int_{0}^t \frac{d}{d\tau} ( e^\tau s(\tau)) d\tau = e^t s(t) - s(0) =  \int_0^t e^\tau |\tau| d\tau.$$
Thus $$s(t) = e^{-t} s(0) + e^{-t} \int_0^t e^{\tau} |\tau| d\tau.$$
Note that when $t > 0$ is positive we have $$s(t) = e^{-t} s(0) + e^{-t} \int_0^t e^{\tau} \tau d\tau,$$ and when $t < 0$ we have $$s(t) = e^{-t} s(0) - e^{-t} \int_0^t e^{\tau} \tau d\tau.$$
In either case, $\int_0^t e^{\tau} \tau d\tau = \left.\tau e^{\tau}\right|_0^t - \int_0^t e^{\tau} d\tau=te^{t} - \left( e^t - 1 \right)$

Combining the results we have:
$$s(t) = e^{-t} s(0) + t - 1 + e^{-t},$$ when $t> 0$, and $$s(t) = e^{-t} s(0) - t + 1 - e^{-t},$$ when $t< 0$.

Finally taking into account $s(0) = 1$:
$$s(t) = 2e^{-t}  + t - 1,$$ when $t> 0$, and $$s(t) =  - t + 1,$$ when $t< 0$.
