Solving initial value problem

Im solving initial value problem $$\frac {dy}{dx} + xy = xy^2; y(0)=3$$ After applying Bernoulli's equation method i obtained $$\frac {dv}{dx} -xv = -x$$ So, $$p(x) = -x, q(x) = -x$$ For finding integrating factor $$u(x)=e^ {-\int xdx}=e^ {-\frac {x^2}{2}}$$ $$y= \frac {\int u(x)q(x)dx+C}{u(x)}={\int u(x)q(x)dx}$$ So, $$-\int xe^ {-\frac {x^2}{2}}dx$$ Please help further or guide me if i did something wrong.

-
$\int u(x) q(x) dx \ne - \int e^{-x^2/2} dx$. – Hans Engler Nov 23 '12 at 15:37
Sorry, I didn't get it, how? – TPSstar Nov 23 '12 at 15:38
$q(x) = -x$, not $q(x) = -1$. Check all your steps. The integral can then be found in closed form. – Hans Engler Nov 23 '12 at 16:15
Thanks i didn't notice that :) – TPSstar Nov 23 '12 at 16:51

This seems fine. the only point is $v=\frac1y$, so $y=\frac1v$ and $$u(x)v(x)-1\cdot\frac13=u(x)v(x)-u(0)v(0)=\int_0^x (u(t)v(t))'=\int_0^x u(t)q(t)dt=-\int_0^x te^{-\frac{t^2}{2}}dt$$ So $$v(x)=e^{\frac{x^2}{2}}\left(\frac13-\int_0^x te^{-\frac{t^2}{2}}dt\right),\hspace{10pt} y(x)=\frac{1}{v(x)}$$

-
How do we plug y(0)=3 in equation? – TPSstar Nov 23 '12 at 15:32
Since $v=\frac1y$, we have $v(0)=\frac13$ and I used it at the very beginning of the first line. – Dennis Gulko Nov 23 '12 at 15:37
Thank you got it :) – TPSstar Nov 23 '12 at 15:39

Why don't you try separation of variables? This leads to a closed form solution that exists for all $x < \sqrt{2 \log \frac{3}{2}}$.

-
In that case there is something wrong. If there is a closed form for $y(x)$, then we can find a closed form for $\int_0^x e^{-\frac{t^2}{2}}dt$, which does not exist. – Dennis Gulko Nov 23 '12 at 15:39
there is an error in the original post, see my comments. – Hans Engler Nov 23 '12 at 16:14

$$\mbox{Set}\ {\rm y}\left(x\right) \equiv {\rm f}\left(x^{2}\right)\equiv{\rm F}\left(x\right)$$

$$\mbox{You get}\quad {\rm F}'\left(x\right) ={{\rm F}^{2}\left(x\right) - {\rm F}\left(x\right)\over 2}$$

-