Solve $y'+2y=\left\{\begin{matrix} 2 ,& 0 \le x <1\\ -2,& x \ge1 \end{matrix}\right.$ Given the first IVP $$y'+2y=\left\{\begin{matrix}
2 ,& 0 \le x <1\\ 
 -2,& x \ge1
\end{matrix}\right.$$
With initial condition $y(0)=2$
1) Find the explicit solution on the interval $0 \le x <1$
2) Find the explicit solution on the interval  $x \ge 1$
For 1) Since I.F =$e^{2x}$
hence $y.e^{2x}=\int ^1_0 2 e^{2x}dx+c\\
y=\frac{e^{2x}+c}{e^{2x}}\\
y=\frac{e^{2x}+1}{e^{2x}}$ for $y(0)=1$
how can we solve (2)
 A: 
You will have the same $c$ as it is about the homogeneous part of the solution, but with a different particular solution ($y_p$).

Here is a classic but general method of solving:


*

*We first find the homogeneous solution of the ODE as below:


$$y'+2y=0$$
$\displaystyle \to \dfrac{y'}{y}=-2 \to \ln(y)=-2x+c \to y_h=ce^{-2x}$


*

*For the particular solution we have:


$$y'+2y=2u(t)-4u(t-1)$$
Now by the method of undetermined coefficients, we conclude that:
$$y_p=\left\{\begin{matrix}
1 ,& 0 \le x <1\\ 
 -1,& x \ge1
\end{matrix}\right.$$


*

*The general solution of ODE is of the form: $y=y_p + y_h$, so:


$$y=\left\{\begin{matrix}
ce^{-2x}+1 ,& 0 \le x <1\\ 
 ce^{-2x}-1,& x \ge1
\end{matrix}\right.$$
For the first part, we know that $y(0)=2$, thus $c+1=2 \to c=1$, hence:
$$y=\left\{\begin{matrix}
e^{-2x}+1 ,& 0 \le x <1\\ 
 e^{-2x}-1,& x \ge1
\end{matrix}\right.$$
Or simply:
$$\displaystyle y=e^{-2x}+u(t)-2u(t-1)$$
A: $$y'+2y=\left\{\begin{matrix}
2 ,& 0 \le x <1\\ 
 -2,& x \ge1
\end{matrix}\right.$$
1) for $0 \le x <1$
$$y'+2y=2$$
$$(ye^{2x})'=2e^{2x}$$
$$y=2e^{-2x}\int e^{2x}dx=2e^{-2x}(\frac {e^{2x}}2+K_1)=K_1e^{-2x}+1$$
$$y(0)=2 \implies K_1+1=2 \implies K_1=1 \implies  y=e^{-2x}+1$$ 
2) for $ x \ge 1$
$$y'+2y=-2$$
$$y'=-2(y+1)$$
$$\int \frac {dy}{(y+1)}=-2x+K_2$$
$$\ln{(y+1)}=-2x+K_2$$
$$y+1=K_2e^{-2x}$$
$$y=K_2e^{-2x}-1$$
For continuity reason we must have at $x=1$
$$K_2e^{-2x}-1=e^{-2x}+1 \implies K_2=1+2e^2$$
$$y=(1+2e^2)e^{-2x}-1$$
Therefore
$$\boxed{y(x)=\left\{
\begin{matrix}
e^{-2x}+1 & 0 \le x < 1 \\ 
 (1+2e^2)e^{-2x}-1 & x \ge 1
\end{matrix}
\right.} 
$$
