Gaining insight into integration factor I just started a course on Differential Equations and am very confused about integration factors. 
I was taught that no set algorithm exists, but if I apply the formula $\frac {X_y-Y_x}{X}$ to the equation and I get a result that only depends on $y$; or conversely, apply the formula $\frac {X_y-Y_x}{Y}$ to the equation and get a result that only depends on $x$, I can use those results as integration factors.
I tried this with the equation $(x+y^2)dy-ydx=0$, and am left with $\frac{-2}{y}$ and $\frac{-2}{x+y^2}$ respectively, where the first one fits the criteria. Yet $e^\frac{-2x}{y}$ does not work to make this formula exact. By fluke I discovered that $\frac{1}{y^2}$ does do the trick, but cannot see how this integration factor is related to the instructions given above. Where is the mistake in my reasoning, and how should I have understood that $\frac{1}{y^2}$ is the correct integration factor?
 A: I think you have an error in your integrating factor.
This is my solution. The ODE to solve is
\begin{align*}
          y \left( x \right) - \left( x+ \left( y \left( x \right)  \right) ^{2} \right) {\frac {\rm d}{{\rm d}x}}y \left( x \right) =0
\end{align*}
The first step is to write the ODE in standard form for exact, which is
$$
           M(x,y) \mathop{\mathrm{d}x}+ N(x,y) \mathop{\mathrm{d}y}=0
$$
Therefore
\begin{align*}
                     \left({y}^{2}+x\right)\mathop{\mathrm{d}y} &= \left(y\right)\mathop{\mathrm{d}x}\\ 
                     \left(-y\right)\mathop{\mathrm{d}x} + \left({y}^{2}+x\right)\mathop{\mathrm{d}y} &= 0 
\end{align*}
Hence from the above
\begin{align*}
               M(x,y) &= -y\\ 
               N(x,y) &= {y}^{2}+x\\ 
\end{align*}
Now the ODE is determined if it is exact or not. The ODE will be exact when
the  following condition is satisfied
$$
             \frac{\partial M}{\partial y} = \frac{\partial N}{\partial x} 
$$
Using the above on the given ODE gives 
\begin{alignat*}{3}
          &\frac{\partial M}{\partial y} &&=  \frac{\partial}{\partial y} \left(-y\right)  &&= -1\\ 
          &\frac{\partial N}{\partial x} &&=  \frac{\partial}{\partial x} \left({y}^{2}+x\right)  &&= 1
\end{alignat*}
Since $\frac{\partial M}{\partial y} \neq \frac{\partial N}{\partial x}$
then the ODE is not exact.
Since the ODE is not exact, an integrating factor is found to make it exact.
Let
\begin{align*}
                  A &= \frac{1}{N} \left(\frac{\partial M}{\partial y} - \frac{\partial N}{\partial x}   \right)   \\ 
                    &= \left( {y}^{2}+x \right) ^{-1}\left( \left( -1\right) - \left(1 \right)   \right) \\ 
                    &=-2\, \left( {y}^{2}+x \right) ^{-1}
\end{align*}
Since $A$ depends on $y$, it can not be used to obtain an integrating factor. 
Alternative method is now tried. Let
\begin{align*}
              B &= \frac{1}{M} \left( \frac{\partial N}{\partial x} - \frac{\partial M}{\partial y}  \right)   \\ 
                &=-{y}^{-1}\left( \left( 1\right) - \left(-1   \right)   \right) \\ 
                &=-2\,{y}^{-1}
\end{align*}
Since $B$ does not depend on $x$, it can be used to obtain an integrating factor. 
Let the integrating factor be $\mu$. Then
\begin{align*}
                      \mu &= e^{\int B \mathop{\mathrm{d}y}} \\ 
                           &= e^{\int  -2\,{y}^{-1}\mathop{\mathrm{d}y} }
\end{align*}
The result of integrating gives
\begin{align*}
                         \mu &= e^{-2\,\ln  \left( y \right)  } \\ 
                              &= {y}^{-2}
\end{align*}
$M$ and $N$ are now multiplied by this integrating factor, giving new  $M$ and new $N$
which are called $\overline{M}$ and $\overline{N}$ so not to confuse them with the
original $M$ and $N$
\begin{align*}
                       \overline{M}  &=\mu  M \\ 
                                      &= {y}^{-2}\left(-y\right) \\ 
                                      &= -{y}^{-1}
\end{align*}
and
\begin{align*}
                       \overline{N}   &=\mu  N \\ 
                                       &= {y}^{-2}\left({y}^{2}+x\right) \\ 
                                       &= {\frac {{y}^{2}+x}{{y}^{2}}}
\end{align*}
So now a modified ODE is obtained from the original ODE which will be exact
and can be solved using the standard method. The modified ODE is
\begin{align*}
                         \overline{M} + \overline{N}  \frac{  \mathop{\mathrm{d}y}}{\mathop{\mathrm{d}x}}  &= 0 \\ 
                         \left(-{y}^{-1}\right)  + \left({\frac {{y}^{2}+x}{{y}^{2}}}\right)  \frac{  \mathop{\mathrm{d}y}}{\mathop{\mathrm{d}x}} &= 0  
\end{align*}
                      The following equations are set up to solve for the function 
             $\phi\left(x,y\right)$
\begin{align*}
           \frac{\partial \phi}{\partial x } &= M = -{y}^{-1} \tag{1}\\ 
           \frac{\partial \phi}{\partial y } &= N = {\frac {{y}^{2}+x}{{y}^{2}}} \tag{2}
\end{align*}
Integrating (1) w.r.t $x$ gives
\begin{align*}
       \int \frac{\partial \phi}{\partial x} \mathop{\mathrm{d}x} &= \int -{y}^{-1}\mathop{\mathrm{d}x} \\ 
       \phi &= -{\frac {x}{y}}+ f(y) \tag{3}
\end{align*}
Where $f(y)$ is used for the constant of integration since $\phi$ is a function of 
both $x$ and $y$. 
Taking derivative of (3) w.r.t $y$ gives
\begin{align*}
        \frac{\partial \phi}{\partial y} &= {\frac {x}{{y}^{2}}}+f'(y) \tag{4} \\ 
\end{align*}
But (2) says that $\frac{\partial \phi}{\partial y} = {\frac {{y}^{2}+x}{{y}^{2}}}$. Therefore (4) can be written as
\begin{align*}
        {\frac {{y}^{2}+x}{{y}^{2}}} &= {\frac {x}{{y}^{2}}}+f'(y) \tag{5}
\end{align*}
Solving (5) for $ f'(y)$ gives
\begin{align*}
            f'(y) &= 1
\end{align*}
Integrating the above w.r.t $y$.
\begin{align*}
\int f'(y) \mathop{\mathrm{d}y} &=  \int \left( 1\right) \mathop{\mathrm{d}y} \\ 
        f(y)                   &= y+ C_1
\end{align*}
Where $C_1$ is constant of integration. Substituting result found above for 
$f(y)$ into (3) gives $\phi$
$$
       \phi = -{\frac {x}{y}}+y+ C_1
$$
But since $\phi$ itself is a constant function, then let $\phi=C_0$ where $C_0$ is new constant and combining $C_1$ and $C_0$ constants into new constant $C_1$, the above becomes
$$
       \boxed{C_1 = {\frac {{y}^{2}-x}{y}}}
$$
        The above is the solution of the ODE (left implicit)
