Solving $y' + \frac{1}{2}xy + y^{2} = 0$ I am trying to solve the ODE $$y' + \frac{1}{2}xy + y^{2} = 0.$$ Mathematica gives that the answer is $$y(x) = \frac{e^{-x^2/4}}{C + 2\int_{0}^{x/2}e^{-t^{2}}\, dt}.$$ Of course, if I take this answer and plug it into the ODE, I am able to get the answer, but how does one derive this solution from the ODE?
If I multiply the ODE by $e^{x^{2}/4}$, then $$(e^{x^{2}/4}y)' = -e^{x^{2}/4}y^{2}$$ but then this gives $$e^{x^{2}/4}y = -\int_{0}^{x}e^{s^{2}/4}y(s)^{2}\, ds.$$ How does one get from here to the solution Mathematica gave me?
 A: What you're looking for is an integrating factor.  If you multiply the whole equation by $e^{-x^2/4}$ observe that you can make the simplification
$$
e^{-x^2/4}y' + \frac{1}{2}xe^{-x^2/4} y + e^{-x^2/4}y^2 \;\; \Longrightarrow\;\; e^{-x^2/4}\frac{y'}{y^2} + \frac{1}{2}x e^{-x^2/4} \frac{1}{y} + e^{-x^2/4} \;\; =\;\; 0.
$$
Observe now that we can simplify this expression by rewriting it as 
\begin{eqnarray*}
-e^{-x^2/4}\frac{y'}{y^2} - \frac{1}{2} xe^{-x^2/4} \frac{1}{y} & = & e^{-x^2/4} \\
\frac{d}{dx} \left ( \frac{e^{-x^2/4}}{y} \right ) & = & e^{-x^2/4}.
\end{eqnarray*}
Integrating both sides we obtain
$$
\frac{e^{-x^2/4}}{y} \;\; =\;\; \int_0^{x/2} e^{-t^2} dt + C
$$
and therefore 
$$
y(x) \;\; =\;\; \frac{e^{-x^2/4}}{C + \int_0^{x/2} e^{-t^2}dt}.
$$
A: From the result you obtained, it is quite clear that there is a first change of variable $y=\frac 1z$ which, after simplification gives $$2z'-x z-2=0$$ Integrating $2z'-xz=0$ gives $$z=C e^{\frac{x^2}{4}}$$ and then $$C'=e^{-\frac{x^2}{4}}$$ that is to say $$C=\sqrt{\pi }\, \text{erf}\left(\frac{x}{2}\right)+K$$ and then the result.
