Solve the following ODE: $y'-x^2y+y^2=2x$. 
Solve the following ODE: $y'-x^2y+y^2=2x$.

it seems to be a Riccati equation, but I wasn't able to guess the first solution.
I tried several basic functions but no success so far.
 A: Consider $y_0(x)=x^2$.  Then,
$$y_0'(x)-x^2\,y_0(x)+\big(y_0(x)\big)^2=2x-x^4+x^4=2x\,.$$
Therefore, $y=y_0$ is a solution.
How did I get $y_0$?  I simply asserted that $y_0(x)=x^k$ is a solution for some real number $k$.  Then, the differential equation looks like
$$k\,x^{k-1}-x^{k+2}+x^{2k}=2x\,.$$
This seems to work if we can make $k\,x^{k-1}=2x$ and $x^{k+2}=x^{2k}$.  Amazingly, $k=2$ solves both equations.

For the sake of completeness, I shall also solve for a general solution.  Suppose that $y$ is a solution.  Let $z:=y-y_0$.  Then, $$\begin{align}2x&=y'(x)-x^2\,y(x)+\big(y(x)\big)^2\\&=\big(y_0'(x)+z'(x)\big)-x^2\,\big(y_0(x)+z(x)\big)+\big(y_0(x)+z(x)\big)^2\\&=\Big(y_0'(x)-x^2\,y_0(x)+\big(y_0(x)\big)^2\Big)+\big(z'(x)-x^2\,z(x)+2\,y_0(x)\,z(x)+\big(z(x)\big)^2\Big)\\&=2x-\big(z(x)\big)^2\,\Big(w'(x)-\big(2\,y_0(x)-x^2\big)\,w(x)-1\Big)\,,\end{align}$$ where $w(x):=\dfrac{1}{z(x)}$.  Consequently, $$w'(x)-x^2\,w(x)=w'(x)-\big(2\,y_0(x)-x^2\big)\,w(x)=1\,.$$  Then, $$\frac{\text{d}}{\text{d}x}\,\Biggl(\exp\left(-\frac{x^3}{3}\right)\,w(x)\Biggr)=\exp\left(-\frac{x^3}{3}\right)\,,$$ meaning that $$w(x)=\exp\left(+\frac{x^3}{3}\right)\,\left(\int_0^x\,\exp\left(-\frac{t^3}{3}\right)\,\text{d}t+c\right)$$ for some constant $c$.  Thus, \begin{align}y(x)&=y_0(x)+z(x)=y_0(x)+\frac{1}{w(x)}\\&=x^2+\frac{1}{\exp\left(+\frac{x^3}{3}\right)\,\left(\int_0^x\,\exp\left(-\frac{t^3}{3}\right)\,\text{d}t+c\right)}\\&=x^2+\frac{\exp\left(-\frac{x^3}{3}\right)}{\int_0^x\,\exp\left(-\frac{t^3}{3}\right)\,\text{d}t+c}\,.\end{align}  The constant $c$ can be any real number, as well as $\infty$ (in which case, we obtain $y=y_0$)

A: You can always try the second way with the substitution $y=\frac{u'}{u}$ resulting in the linear 2nd order DE
$$
0=u''-x^2u'-2xu=(u'-x^2u)'
\\
\implies u'-x^2u=A
\\
\implies e^{-x^3/3}u(x)=A\int_0^xe^{-s^3/3}ds+B
$$
giving solutions $u=Ae^{x^3/3}\int_0^xe^{-s^3/3}ds+Be^{x^3/3}$. Then
$$
u'=A+x^2u\implies y=x^2+\frac{A}{Ae^{x^3/3}\int_0^xe^{-s^3/3}ds+Be^{x^3/3}}
$$
giving $y_0=x^2$ for $A=0$.
A: Another way:
$$y'-x^2y+y^2=2x$$
$$(y'-2x)-y(x^2-y)=0$$
That you can rewrite as
$$(y-x^2)'+y(y-x^2)=0$$
Substitute $u=y-x^2$
$$u'+x^2u+u^2=0$$
It's Bernouilli's equation. 
$$ \dfrac {du}{u^2}+\left (\dfrac {x^2}u+1 \right )dx=0$$
$$ \dfrac {e^{-x^3/3}du}{u^2}+e^{-x^3/3}\left (\dfrac {x^2}u+1 \right )dx=0$$
$$ d\left (\dfrac {-e^{-x^3/3}}u \right )+e^{-x^3/3}dx=0$$
Integrate.
$$ -e^{-x^3/3}+(y-x^2)\left(\int e^{-x^3/3}dx+c \right )=0$$
Finally:
$$ \boxed {y(x)= x^2+\dfrac {e^{-x^3/3}}{\left(\int e^{-x^3/3}dx+c \right )}}$$
