2.4   ODE No. 4

\[ -e^{-x^2} x+y'(x)+2 x y(x)=0 \]

Mathematica : cpu = 0.0335225 (sec), leaf count = 30

DSolve[-(x/E^x^2) + 2*x*y[x] + Derivative[1][y][x] == 0,y[x],x]
 
\[\left \{\left \{y(x)\to \frac {1}{2} e^{-x^2} x^2+c_1 e^{-x^2}\right \}\right \}\]

Maple : cpu = 0.004 (sec), leaf count = 18

dsolve(diff(y(x),x)+2*x*y(x)-x*exp(-x^2) = 0,y(x))
 
\[y \left (x \right ) = \left (\frac {x^{2}}{2}+c_{1} \right ) {\mathrm e}^{-x^{2}}\]

Hand solution

\begin{equation} \frac {dy}{dx}+2xy\left ( x\right ) =e^{-x^{2}}x \tag {1}\end{equation}

Integrating factor \(\mu =e^{\int 2xdx}=e^{x^{2}}\). Hence (1) becomes

\begin{align*} \frac {d}{dx}\left ( e^{x^{2}}y\left ( x\right ) \right ) & =e^{x^{2}}e^{-x^{2}}x\\ \frac {d}{dx}\left ( e^{x^{2}}y\left ( x\right ) \right ) & =x \end{align*}

Integrating both sides

\begin{align*} e^{x^{2}}y\left ( x\right ) & =\frac {x^{2}}{2}+C\\ y\left ( x\right ) & =e^{-x^{2}}\left ( \frac {x^{2}}{2}+C\right ) \end{align*}