I am trying to find the general solution of $xy' - 2y = -x$.
I normalize the equation to get $y' - \frac{2}{x}y = -1$.
I get the integrating factor as $x^{-2}$, and so $y = x^{2}\int x^{-2}*(-1)\,dx $.
Solving for this integral, I get $ y = x + \frac{C}{x^2}$, but this is not the answer I get on wolfram, which is $Cx^2 +x$. I'd like to know where I'm going wrong.
After dividing both sides by $x$ you get
$$y'(x) - \frac{2}{x}y(x) = -1$$
The integrating factor is
$$\mu(x) = e^{\int -\frac{2}{x}\ dx} = \frac{1}{x^2}$$
Then by following the procedure, you multiply both sides by $\mu(x)$:
$$\frac{1}{x^2}y'(x) - \frac{2}{x^3}y(x) = -\frac{1}{x^2}$$
Use the tricky substitution:
$$-\frac{2}{x^3} = \frac{d}{dx} \frac{1}{x^2}$$
To get
$$\frac{1}{x^2} y'(x) + \frac{d}{dx} \left(\frac{1}{x^2}\right) y(x) = -\frac{1}{x^2}$$
Now in the central term, we apply the reverse product rule:
$$f g' = (fg)' - f'g$$
This will help you to get rid of the first term. Now integrate what remains with respect to $x$:
$$\int \frac{d}{dx}\left(\frac{y(x)}{x^2}\right) \ dx = \int -\frac{1}{x^2}\ dx$$
Easily:
$$\frac{y(x)}{x^2} = \frac{1}{x} + C$$
Hence
$$\color{red}{y(x) = x + Cx^2}$$