Solve the initial value problem: ODE with discontinuous coefficients? 
Solve the initial value problem
  $$
y'-y = \left\lbrace
\begin{aligned}
&1 & & \text{when}\quad 0<t<1 \\
&0 & & \text{when}\quad t>1
\end{aligned}
\right.
,\qquad
y(0)=0 \, .
$$

So I understand that $p(t)=-1$ and $g(t)$ is $1$ and $0$ (depending on the $t$ value), and that I'm supposed to solve it as two separate DEs. I got for the first case that $y=-1$ and for the second case that $y=0$. 


*

*Is this correct?

*Is this the solution? Or do I have to do something with the initial value $y(0)=0$?


Any help is appreciated !!
 A: Define
\begin{equation}
f(t) \;=\;
\begin{cases}
1 & 0 < t < 1\\
0 & t > 1
\end{cases}\, .
\end{equation}
Then, we have
$$
\frac{dy}{dt} - y \;=\; f(t)\, .
$$
Multiply both sides of this by $e^{-t}$:
\begin{equation}
e^{-t}\left(\frac{dy}{dt} - y\right)\;=\;
\frac{d}{dt}\left(e^{-t} y\right) \;=\; e^{-t} f(t)
\end{equation}
Now integrate both sides of this from $0$ to $t$ (using $s$ as a dummy variable of integration):
\begin{equation}
\int_0^t \frac{d}{ds}\Bigl(e^{-s} y(s)\Bigr) \, ds
\;=\;
e^{-s} y(s) \Biggr\vert_{s = 0}^{s = t}
\;=\;
e^{-t} y(t) \;-\; y(0)
\;=\;
\int_0^t e^{-s} f(s)\, ds
\end{equation}
Using $y(0) = 0$, this can be rearranged into
\begin{align}
y(t) &\;=\;
\int_0^t e^{t-s} f(s)\, ds\\
&\;=\;
\int_0^{\min(t,1)} e^{t-s}\, ds \qquad\qquad \text{(Using the definition of $f$)}\\
&\;=\;
e^t \;-\; e^{t - \min(t,1)}\\
&\;=\;
\begin{cases}
e^t - 1 & t < 1\\
e^t\left(1 - 1/e\right) & t > 1
\end{cases}
\end{align}
Note that this solution is continuous at $t = 1$, as it should be.
A: I would do this as two separate problems.  First solve y'- y= 1, y(0)= 0.  That is a non-homogeneous differential equation. The solution to the associated homogeneous equation, y'- y= 0, is $y(t)= Ce^t$ for C an arbitrary constaant.  If we try y= A, a constant for the entire equation, we get -A= 1 so A= -1.  The general solution to the first equation if $y(t)= Ce^t- 1$.  With initial condition $y(0)= C- 1= 0$, C= 1.  The solution to this initial value problem is $y(t)= e^t- 1$.
Now look at the second equation, y'- y= 0.  The general solution to that is $y(t)= Be^t$.  To determine B we need an initial value, a value at t= 1.  Since we must have the derivatives existing, y must be continuous so $y(1)= Be= e- 1$ from the previous solution.  We must have $B= (e- 1)/e= 1- e^{-1}$.  The solution to this initial value problem is $y(t)= (1- e^{-1})e^t= e^{t}- e^{t-1}$.
The solution to the original problem is
$y(t)= e^t- 1$ for $t\le 1$
$y(t)= e^{t}- e^{t- 1}$ for $t> 1$.
A: For the first case $(t<1)$, you should have:
$$y'-y=1$$
$$\int \dfrac {dy}{1+y}=t+K$$
$$\ln(y+1)=t+K$$
$$(y+1)=e^{t+K}=Ke^t$$
$$y=Ke^t-1$$
Since $y(0)=0 \implies K=1$
$$\boxed{y=e^t-1}$$
