(For convenience, for any functions, only its first instance the x,y dependence will be written out, all subsequent instance the x,y will be suppressed)
I have an ODE $$M(x,y)+N(x,y)\frac{dy}{dx}=0$$
I understood the ODE is inexact when $$\frac{\partial M}{\partial y} \neq \frac{\partial N}{\partial x}$$
I also learnt that for some inexact ODE, it can be made exact if the integrating factor $\mu$ is a function of x or y only, which is determined if the first (resp second) of these is satisfied
$$\frac{\frac{\partial M}{\partial y}-\frac{\partial N}{\partial x}}{M},\frac{\frac{\partial M}{\partial y}-\frac{\partial N}{\partial x}}{N}$$
So that a function
$$H(x,y)=C$$
can be found as the solution to the ODE
However when I tried to do it as a general $\mu (x,y)$ I got something interesting
Start with
$$M(x,y)+N(x,y)\frac{dy}{dx}=0$$
ODE is exact with integrating factor $\mu$ iff
$$\frac{\partial (\mu M)}{\partial y} = \frac{\partial (\mu N)}{\partial x}$$
$$\mu\frac{\partial M}{\partial y}+\frac{\partial \mu}{\partial y}M = \mu\frac{\partial N}{\partial x}+\frac{\partial \mu}{\partial x}N$$
Rearrange
$$\mu\left(\frac{\partial M}{\partial y}-\frac{\partial N}{\partial x}\right) =\frac{\partial \mu}{\partial x}N-\frac{\partial \mu}{\partial y}M$$
Rewrite with del operators
$$\mu \nabla \cdot \begin{pmatrix} M \\ -N \end{pmatrix} =\nabla\mu \cdot \begin{pmatrix} N \\ -M \end{pmatrix}$$
Move everything to the LHS and move the - sign into the vectors
$$\mu \nabla \cdot \begin{pmatrix} M \\ -N \end{pmatrix} + \nabla\mu \cdot \begin{pmatrix} -N \\ M \end{pmatrix}= 0$$
This thing
$$\mu \nabla \cdot \begin{pmatrix} M \\ -N \end{pmatrix} + \nabla\mu \cdot \begin{pmatrix} -N \\ M \end{pmatrix}= 0$$
looks deceptively similar to the divergence product rule, is it actually possible to do something on it and solve it analytically for $\mu$?
================================================================== UPDATE
KittyL have pointed out a mistake I made in the 1st version. It is now corrected as follows
$$\mu \nabla \cdot \begin{pmatrix} \color{red}{-N} \\ \color{red}{M} \end{pmatrix} =\nabla\mu \cdot \begin{pmatrix} N \\ -M \end{pmatrix}$$
which rearranges to
$$\mu \nabla \cdot \begin{pmatrix} N \\ -M \end{pmatrix} +\nabla\mu \cdot \begin{pmatrix} N \\ -M \end{pmatrix}=0$$
Using the divergence product rule backwards
$$ \nabla \cdot \left(\mu\begin{pmatrix} N \\ -M \end{pmatrix}\right)=0$$
Since the starting functions M,N,$\mu$ are all functions of two variables (e.g. x,y) we can say this problem lives in $\mathbb{R}^2$
Applying Divergence theorem in $\mathbb{R}^2$
$$ \iint_A\nabla \cdot \left(\mu\begin{pmatrix} N \\ -M \end{pmatrix}\right)dA=\iint_A 0 dA$$
$$ \oint \mu\begin{pmatrix} N \\ -M \end{pmatrix}\cdot d\vec{l}=0$$
Because divergence theorem holds for all closed surfaces, let's choose our surface to be a circle $x^2+y^2=1$
Parametrising in terms of $\theta$, we obtained
$$ \int_0^{2\pi} \mu(r,\theta)\begin{pmatrix} N(r,\theta) \\ -M(r,\theta) \end{pmatrix}\cdot \frac{\nabla{r^2}}{||\nabla{r^2}||}d\theta=0$$
$$ \int_0^{2\pi} \mu(r,\theta)\begin{pmatrix} N(r,\theta) \\ -M(r,\theta) \end{pmatrix}\cdot \frac{1}{\sqrt{2r}}\begin{pmatrix} \cos\theta \\ \sin\theta \end{pmatrix}d\theta=0$$
$$ \int_0^{2\pi} \frac{\mu(r,\theta)}{\sqrt{2r}}\left( N(r,\theta)\cos\theta-M(r,\theta)\sin\theta\right)d\theta=0$$
Is there a non trivial solution to $\mu$ for this integral?
If so, can $\mu$ be solved analytically/in a closed form?
If no analytic solutions exists in general, what is the most numerically stable and efficient way to approximate $\mu$?
$$ \int_0^{2\pi} \frac{\mu(r,\theta)}{\sqrt{2r}}\left( N(r,\theta)\cos\theta-M(r,\theta)\sin\theta\right)d\theta=0$$