ODE No. 18

\[ y'(x)-y(x)^2-x y(x)-x+1=0 \] Mathematica : cpu = 0.0917731 (sec), leaf count = 50

DSolve[1 - x - x*y[x] - y[x]^2 + Derivative[1][y][x] == 0,y[x],x]
 

\[\left \{\left \{y(x)\to -1+\frac {e^{\frac {x^2}{2}-2 x}}{-\frac {\sqrt {\frac {\pi }{2}} \text {erfi}\left (\frac {x-2}{\sqrt {2}}\right )}{e^2}+c_1}\right \}\right \}\] Maple : cpu = 0.079 (sec), leaf count = 39

dsolve(diff(y(x),x)-y(x)^2-x*y(x)-x+1 = 0,y(x))
 

\[y \left (x \right ) = -1+\frac {{\mathrm e}^{\frac {x \left (x -4\right )}{2}}}{c_{1}+\frac {i \sqrt {\pi }\, {\mathrm e}^{-2} \sqrt {2}\, \erf \left (\frac {i \sqrt {2}\, \left (x -2\right )}{2}\right )}{2}}\]

Hand solution

\begin {align} y^{\prime }-y^{2}-xy-x+1 & =0\nonumber \\ y^{\prime } & =x-1+xy+y^{2}\tag {1} \end {align}

This is Riccati first order non-linear ODE of the form. The general form is\[ y^{\prime }=P\left ( x\right ) +Q\left ( x\right ) y+R\left ( x\right ) y^{2}\] Where \(P\left ( x\right ) =x-1,Q\left ( x\right ) =x,R\left ( x\right ) =1\). We see that \(y_{p}=-1\) is a particular solution, therefore we use the substitution \(y=y_{p}+\frac {1}{u}\), hence \(y^{\prime }=-\frac {u^{\prime }}{u^{2}}\) and equating this to (1) we obtain\begin {align*} -\frac {u^{\prime }}{u^{2}} & =x-1+xy+y^{2}\\ & =x-1+x\left ( -1+\frac {1}{u}\right ) +\left ( -1+\frac {1}{u}\right ) ^{2}\\ & =x-1-x+\frac {x}{u}+\left ( 1+\frac {1}{u^{2}}-\frac {2}{u}\right ) \\ & =\frac {x}{u}+\frac {1}{u^{2}}-\frac {2}{u} \end {align*}

Hence\begin {align*} u^{\prime } & =-u^{2}\left ( \frac {x}{u}+\frac {1}{u^{2}}-\frac {2}{u}\right ) \\ & =-xu-1+2u\\ u^{\prime }+xu-2u & =-1\\ u^{\prime }+u\left ( x-2\right ) & =-1 \end {align*}

Integration factor is \(e^{\int \left ( x-2\right ) dx}=e^{\frac {x^{2}}{2}-2x}=e^{\frac {1}{2}x\left ( x-4\right ) }\), therefore\[ d\left ( e^{\frac {1}{2}x\left ( x-4\right ) }u\right ) =-e^{\frac {1}{2}x\left ( x-4\right ) }\] Integrating both sides\[ e^{\frac {1}{2}x\left ( x-4\right ) }u=-\int e^{\frac {1}{2}x\left ( x-4\right ) }+C \] But \[ \int e^{\frac {1}{2}x\left ( x-4\right ) }=\frac {1}{e^{2}}\sqrt {\frac {\pi }{2}}\operatorname {erfi}\left ( \frac {x-2}{\sqrt {2}}\right ) \] Hence\[ u\left ( x\right ) =e^{\frac {-1}{2}x\left ( x-4\right ) }\left ( \frac {-1}{e^{2}}\sqrt {\frac {\pi }{2}}\operatorname {erfi}\left ( \frac {x-2}{\sqrt {2}}\right ) +C\right ) \] Since \(y=y_{p}+\frac {1}{u}\) then\[ y=-1+\frac {1}{e^{\frac {-1}{2}x\left ( x-4\right ) }\left ( \frac {-1}{e^{2}}\sqrt {\frac {\pi }{2}}\operatorname {erfi}\left ( \frac {x-2}{\sqrt {2}}\right ) +C\right ) }\] Or\[ y=\frac {e^{\frac {1}{2}x\left ( x-4\right ) }}{C-\frac {1}{e^{2}}\sqrt {\frac {\pi }{2}}\operatorname {erfi}\left ( \frac {x-2}{\sqrt {2}}\right ) }-1 \]