What to do when the integrating factor is a function of both x and y? I have to solve the following differential equation:
$$(\cos^2x + y \sin 2x) \frac{dy}{dx} + y^2 =0$$
using an integrating factor. An integrating factor that is a function of just $x$ or just $y$ won't work, so we need to find an integrating factor which is a function of both $x$ and $y$. 
I have followed the instructions from this other post Finding integrating factor when IF will be a function of x and y which suggests looking for a separable solution:
$$u(x,y)=e^{\int G(x) dx} e^{\int F(y) dy}$$
where $G(x)=\frac{\delta u/\delta x}{u}$ and $F(y)=\frac{\delta u/\delta y}{u}$. However, I get stuck at this point:
$$G(x)(\cos^2 x + y \sin 2x) - F(y) y^2 = 2y + 2 \sin 2x - 2y \cos 2x$$
and I can't find a solution for $G(x)$ and $F(y)$ that would work. 
Any ideas? Thanks in advance!
 A: Let's rewrite the equation in this form:
\begin{equation*}
\underbrace{y^2}_M \,\mathrm dx + \underbrace{(\cos^2 x + y \sin 2x)}_N \,\mathrm dy = 0.
\end{equation*}
Let $u(x,y)$ be an integrating factor. Then after multiplying the above equation by $u$, the resulting equation $uM \,\mathrm dx + uN \,\mathrm dy = 0$ should be exact. Thus, we must have
\begin{align*}
\dfrac{\partial (uM)}{\partial y} = \dfrac{\partial (uN)}{\partial x} \implies\\
u M_y + u_y M = u N_x + u_x N \implies\\
u(M_y - N_x) = u_x N - u_y M.
\end{align*}
Since $M = y^2$ and $N = \cos^2 x + y \sin 2x$, we have $M_y = 2y$ and $N_x = - \sin 2x + 2y \cos2x$, so that $M_y - N_x = \sin 2x + 2y (1 - \cos 2x) = 2\sin x \cos x + 4y \sin^2 x = 2\sin x (\cos x + 2y \sin x)$.
Note that $N = \cos^2 + 2y \sin x \cos x = \cos x (\cos x + 2y \sin x)$.
Thus, we have
\begin{align*}
M_y - N_x & = 2 \sin x (\cos x + 2y \sin x)\\
N & = \cos x (\cos x + 2y \sin x).
\end{align*}
Now, if it happened that $u$ were only a function of $x$, then $u_y = 0$, and our earlier condition for exactness would become
\begin{equation*}
u(M_y - N_x) = u_x N \implies \dfrac{u_x}{u} = \dfrac{M_y - N_x}{N}.
\end{equation*}
Indeed, this would be true if the RHS turned out to be a function of $x$ alone. Observe that this is so, for $\dfrac{M_y - N_x}{N} = 2 \tan x$.
Thus, $$\dfrac{u_x}{u} = 2 \tan x \implies \log u = \int 2 \tan x \,\mathrm dx = 2 \log \sec x.$$ Therefore, $$u = \sec^2 x$$ is the integrating factor.
