intial value piecwise linear ODE; slightly wrong answer Where am I going wrong?
Solve the given initial value problem. Use a graphing utility to graph the continuous function y(x).
$\frac{dy}{dx} +2xy=f(x),y(0)=2$ where $f(x)=\left\{
     \begin{array}{lr}
       x, & 0 \leq x \leq 1\\
       0, & x \gt 1
     \end{array}
   \right.$
I did $\frac{dy}{dx}+2xy=x$  for $0 \leq x \leq 1 $
$P(x) = 2x$ then $\int P(x) dx = x^2$ and $f(x) = x$
$\frac{d}{dx} [ e^{P(x)dx}y]=e^{\int P(x)dx}f(x)$
$\frac{d}{dx}[e^{x^2}y]=e^{x^2}x$
$\int \frac{d}{dx}[e^{x^2}y] dx =\int e^{x^2}x dx$
$e^{x^2}y = \frac{e^{x^2}}{2}+C$
Rewriting $C = \frac{1}{2}+Ce^{-x^2}$
Then for $x>1$ $\frac{dy}{dx}+2xy=0$ and $P(x)= 2x$ then $\int P(x) dx = x^2$ and $f(x)=0$
$\frac{d}{dx} [ e^{P(x)dx}y]=e^{\int P(x)dx}f(x)$
$\frac{d}{dx}[e^{x^2}y]=e^{x^2}0=0$
$\int \frac{d}{dx}[e^{x^2}y] dx= \int 0 dx = C$
rewriting $e^{x^2}y=C$ so $y=Ce^{-x^2}$ and applying $y(0)=2$ gives
 $2=C^{-0^2}=C$
So then 
$y=\left\{
     \begin{array}{lr}
       \frac{1}{2}+2e^{-x^2} & -1 \leq x \leq 1 \\
       2e^{-x^2} & x > 1 \\
     \end{array}
   \right.$
But the answer key gives
$y=\left\{
     \begin{array}{lr}
       \frac{1}{2}+\frac{3}{2}e^{-x^2} & -1 \leq x < 1 \\
       (\frac{1}{2} e + \frac{3}{2})e^{-x^2} & x \ge 1 \\
     \end{array}
   \right.$

where you went wrong is applying $y(0) = 2$ to the solution that applies for $x>1$.  You should have applied it to the solution that applis for $x<1$, giving $\frac{1}{2} + C = 2$.  This gives the answer that appears in the key.
