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)
$$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.} $$