Differential Equations  I have solve this differential equation :
$$\left\{\begin{aligned}\frac{dy}{dx} + y &= f(x) \\
y (0)&=0.
\end{aligned}\right.$$ 
where $f (x) = \begin{cases}2 & \text{if } 0 \leq x < 1 \\
0 &\text{if }x \geq 1.\end{cases}$
Please explain how to solve as it involves discontinuous function $f$. 

Multiply by the integrating factor $e^x$ and then you can factor the LHS: $$(e^xy)'=e^xf(x).$$ Now integrate from $0$ to $x$ to get $$e^xy(x)-e^0y(0)=\int_0^xe^uf(u)du$$ 
but remember $y(0)=0$. Now divide by the integrating factor and you have $y(x)=e^{-x}\int_0^xe^uf(u)du$. We can evaluate this by (a) looking at $x\in[0,1)$ and then (b) looking at $x\ge1$ for a piecewised defined solution $y$ (note: in the latter case you will have to split $\int_0^x$ into $\int_0^1+\int_1^x$ to substitute for $f$).
