# how to solve this linear differential equation

the differential equation is :

$$\frac{dy}{dx}+y=f(x),~~~~~~~~ y(0)=0$$

where,

$$f(x)=\cases{2,& if 0\le x\lt1\\0,& if x\ge 1}.$$

So what i did was....

since it is a linear differential equation, i calculated its I.F(integrating factor)= $e^x$

and used..

$$y(I.F)=\int (e^x f(x)+c\tag{1})\,dx.$$

Now, how should i use the splitting of $f(x)$ to solve for $y$ in $(1)$

• write up two solution in the different range and match them at the boundary by requiring $y$ to be continuous. the derivative will certainly have a jump. – abel Jan 20 '15 at 16:29
solving for $y$ in the interval $[0,1],$ you find $y = 2 -2 e^{-x}$ and $y(1) = 2 - 2/e.$ use this as the initial value and solve $\dfrac{dy}{dx} + y = 0$ to get $y = 2(e-1)e^{-x}$ for $x \ge 1$.