Finding a continuous function that satisfies a first order differential equation I'm looking for a continuous function to satisfy the O.D.E.:
$$(1+x^2)\frac{dy}{dx}+2xy=f(x);\:f(x)=x\:\:\text{for}\:\: 0\leq x <1;\ f(x)=-x\:\:\text{for} \:\:x>1 ;\ y(0)=0.$$
In my attempt to solve this I separated the problem into two cases: $f(x)=x$ and $f(x)=-x$, and I found that in the first case $y=\frac{x^2}{2(x^2+1)}$ and in the second case $y=-\frac{x^2}{2(x^2+1)}$.  I'm confused as to how to obtain a solution that is one continuous function, as these two functions only intersect at $(0,0)$. 
 A: It looks like you're most of the way there.  First of all, you forgot about the constants of integration.  What you have is $y(x)=\frac{x^2+k_1}{2(x^2+1)}$ when $0\le x<1$ and $-\frac{x^2+k_2}{2(x^2+1)}$ when $x>1$.  First, use your initial condition to solve for $k_1$.  If you want your function to be continuous at $x=1$, you will want
$$\lim_{x\to1^{-}}y(x)=\lim_{x\to1^+}y(x)$$
You should be able to use this to solve for $k_2$.
A: Rather than separate the cases, solve the differential equation directly and worry about $f$ later. Observe that
$$\frac{d}{dx}((1+x^2)y)=(1+x^2)\frac{dy}{dx}+2xy=f(x)$$
and so by integrating both sides from $0$ to $x$ we get
$$(1+x^2)y-(1+0^2)y(0)=\int_0^xf(\bar{x})\ d\bar{x}$$
and so
$$y=\frac{g(x)}{1+x^2}$$
is the unique solution, where $g(x)=\int_0^xf(t)dt$. Since $f$ is Riemann integrable, $g$ is continuous - you might like to try to prove this. But in this case we can find $g$ explicitly. For $0\le x\le1$, $f(t)=t$ for all $t\in(0,x)$ so $g(x)=\frac12x^2$. For $x>1$, we have
$$g(x)=\int_0^1t\ dt+\int_1^x(-t)\ dt=\frac12+\left(-\frac{x^2-1}2\right)=1-\frac{x^2}2.$$
Clearly $g$ is continuous everywhere except $x=1$, and at $x=1$ we can evaluate both limits individually and find $g(1^-)=g(1^+)=\frac12$. Hence $g$ is continuous and so $y$ must be as well.
