How to find the general solution to this differential equation? $$\frac{dy}{dx}= (1+x)y+xy^{2}$$
The equation can be formatted to a Bernoulli equation, in the form
$$\frac{dy}{dx}-(1+x)y = xy^{2}$$
However, attempting this any further leads to integrating $$-xe^{(x+\frac{x^{2}}{2})}$$ which leads me to believe I am not attempting this equation correctly.
 A: The differential equation has the form $y'+a(x)y=b(x)y^{\alpha}$ which is Bernoulli as you said. The standard method of solution is to make the substitution $\phi=y^{1-\alpha}$.
We have $$y'-(1+x)y=xy^{2}\tag{1}$$
Setting $\phi=y^{1-2}=y^{-1}$ then $\phi'=-y^{-2}y'$ and $(1)$ can be written as
$$\phi'+(x+1)\phi=-x \tag{2}$$
which is a linear differential equation and can be solved using integrating factor.
Let the integrating factor $\mu(x)=e^{\int (x+1)\, dx}=e^{\frac{x^{2}}{2}+x }$ and then multiply both sides of $(2)$ by $\mu(x)$ we have
$$e^{\frac{x^{2}}{2}+x}\left(\phi'+(x+1)\phi \right) =-xe^{\frac{x^{2}}{2}+x}$$
that can be written as
$$\frac{d}{dx}\left(\phi e^{\frac{x^{2}}{2}+x} \right)=-xe^{\frac{x^{2}}{2}+x}\tag{3}$$
Integrating $(3)$ we have
$$e^{\frac{x^{2}}{2}+x}\phi=\int -x e^{\frac{x^{2}}{2}+x}\, dx+C.$$
Since $\phi=y^{-1}$, then we have the integral representation solution
$$y^{-1}(x)=\frac{1}{e^{\frac{x^{2}}{2}+x}}\left( \int-x e^{\frac{x^{2}}{2}+x}\, dx+C\right).$$
That is,
$$y(x)=\frac{1}{\frac{1}{e^{\frac{x^{2}}{2}+x}}\left( \int-x e^{\frac{x^{2}}{2}+x}\, dx+C\right)}$$
Using the fact ${\rm erf}(z)=\frac{2}{\sqrt{\pi}}\int_{0}^{z}e^{-t^{2}}\, dt$, and ${\rm erfi}(z)=-i {\rm erf}(iz)$ with $i$ the imaginary unity we can show that
$$\int -xe^{\frac{x^{2}}{2}+x}dx=\sqrt{\frac{\pi}{2e}}{\rm erfi}\left(\frac{x+1}{\sqrt{2}} \right)-e^{\frac{x^{2}}{2}+x}$$
Hence the general solution can be written as
$$y(x)=\frac{-2e^{\frac{x^{2}}{2}+x}}{2e^{\frac{x^{2}}{2}+x}-\sqrt{\frac{2\pi}{e}} {\rm erfi}\left(\frac{x+1}{\sqrt{2}}\right)+C}$$
