##### 4.4.37 $$x y'(x)=a x^n (x-y(x))^2-y(x)+2 x$$

ODE
$x y'(x)=a x^n (x-y(x))^2-y(x)+2 x$ ODE Classiﬁcation

[[_1st_order, _with_linear_symmetries], _rational, _Riccati]

Book solution method
Riccati ODE, Generalized ODE

Mathematica
cpu = 0.731271 (sec), leaf count = 126

$\left \{\left \{y(x)\to \frac {x^{-n} \left (2 a x^{n+\sqrt {(n-1)^2}+1}+2 a c_1 \sqrt {(n-1)^2} x^{n+1}-\left (n+\sqrt {(n-1)^2}-1\right ) x^{\sqrt {(n-1)^2}}-c_1 \left (-n+\sqrt {(n-1)^2}+1\right ) (n-1)\right )}{2 a \left (x^{\sqrt {(n-1)^2}}+c_1 \sqrt {(n-1)^2}\right )}\right \}\right \}$

Maple
cpu = 0.099 (sec), leaf count = 35

$\left [y \left (x \right ) = \frac {x^{n} \textit {\_C1} a x -\textit {\_C1} n -x^{2}+\textit {\_C1}}{x^{n} \textit {\_C1} a -x}\right ]$ Mathematica raw input

DSolve[x*y'[x] == 2*x + a*x^n*(x - y[x])^2 - y[x],y[x],x]

Mathematica raw output

{{y[x] -> (-((-1 + Sqrt[(-1 + n)^2] + n)*x^Sqrt[(-1 + n)^2]) + 2*a*x^(1 + Sqrt[(
-1 + n)^2] + n) - (1 + Sqrt[(-1 + n)^2] - n)*(-1 + n)*C[1] + 2*a*Sqrt[(-1 + n)^2
]*x^(1 + n)*C[1])/(2*a*x^n*(x^Sqrt[(-1 + n)^2] + Sqrt[(-1 + n)^2]*C[1]))}}

Maple raw input

dsolve(x*diff(y(x),x) = 2*x-y(x)+a*x^n*(x-y(x))^2, y(x))

Maple raw output

[y(x) = (x^n*_C1*a*x-_C1*n-x^2+_C1)/(x^n*_C1*a-x)]