# Exact Equations

The differential equation `M(x,y)dx+N(x,y)dy=0` is exact, if there exists a function `f` such that `df=M(x,y)dx+N(x,y)dy`.

In this case, the equation can be rewritten as `df=0`, which gives the solution `f=C`.

**Test for exactness:** if `M(x,y)` and `N(x,y)` are continuous functions and have continuous first partial derivatives on some rectangle of the xy-plane, the differential equation is exact, if and only if `(partial M(x,y))/(partial y)=(partial N(x,y))/(partial x)`.

To solve this equation, we use the facts that `(partial f(x,y))/(partial x)=M(x,y)` and `(partial f(x,y))/(partial y)=N(x,y)`. We integrate the first equation with respect to `x` to obtain `f(x,y)` through `x` and an unknown function `g(y)`. We then differentiate the result with respect to `y` and use the second equation. After this, we find `g(y)`, and thus `f(x,y)`. The solution, as already stated above, is given as `f(x,y)=C`.

**Example 1.** Solve `(x+sin(y))dx+(x cos(y)-2y)dy=0`.

Here, `M(x,y)=x+sin(y)`, `N(x,y)=xcos(y)-2y`. Since `(partial M)/(partial y)=cos(y)` and `(partial N)/(partial x)=cos(y)`, we have that `(partial M)/(partial y)=(partial N)/(partial x)` and the differential equation is exact.

Thus, there exists a function `f` such that `(partial f)/(partial x)=M(x,y)=x+sin(y)` and `(partial f)/(partial y)=N(x,y)=xcos(y)-2y`.

Integrate the first equation with respect to `x` to obtain that `f=int (x+sin(y))dx=1/2 x^2+xsin(y)+g(y)`.

Note that here, the constant of integration can depend on `y` (because we integrate with respect to `x`).

Now, differentiate the resulting equation with respect to `y`:

`(partial f)/(partial y)=0+xcos(y)+g'(y)`.

On the other hand, `(partial f)/(partial y)=N(x,y)=xcos(y)-2y`.

So, `xcos(y)+g'(y)=xcos(y)-2y`, or `g'(y)=-2y`. Integrating it, we obtain that `g(y)=-y^2+c_1`.

Thus,

`f=1/2 x^2+xsin(y)-y^2+c_1`. The solution is given as `1/2 x^2 +xsin(y)-y^2+c_1=C`,

Or `1/2 x^2 +xsin(y)-y^2=c_2`, where (`c_2=C-c_1`).

We obtain an implicit solution, and there is no way to find an explicit solution.

Let's work another example.

**Example 2.** Solve `y'=(2+ye^(xy))/(2y-xe^(xy))`.

First, rewrite it into the differential form: `(dy)/(dx)=(2+ye^(xy))/(2y-xe^(xy))`, or `(2+ye^(xy))dx+(xe^(xy)-2y)dy=0`.

Here, `M(x,y)=2+ye^(xy)`, and `N(x,y)=xe^(xy)-2y`.

Since `(partial M)/(partial y)=e^(xy)+xye^(xy)` and `(partial N)/(partial x)=e^(xy)+xye^(xy)`, we have that`(partial M)/(partial y)=(partial N)/(partial x)` and the differential equation is exact.

So, there exists a function `f` such that `(partial f)/(partial x)=M(x,y)=2+ye^(xy)` and `(partial f)/(partial y)=N(x,y)=xe^(xy)-2y`. In the previous example, we took the first equation and integrated it with respect to `x`. Actually, we could take the second equation and integrate it with respect to `y`. The final answer is the same. In this example, we will take the second equation and integrate it with respect to `y`:

`f=int (xe^(xy)-2y)dy=e^(xy)-y^2+g(x)`. Note that the constant of integration depends on `x`, since we integrate with respect to `y`.

Now, differentiate the resulting equation with respect to `x`:

`(partial f)/(partial x)=y e^(xy)+g'(x)`.

On the other hand, `(partial f)/(partial x)=2+ye^(xy)`; so, `ye^(xy)+g'(x)=2+ye^(xy)`, or `g'(x)=2`.

Integrating with respect to `x` gives `g(x)=2x+c_1`.

So, `f=e^(xy)-y^2+g(x)=e^(xy)-y^2+2x+c_1`.

And the solution is `e^(xy)-y^2+2x+c_1=C` or `e^(xy)-y^2+2x=c_2`, where `c_2=C-c_1`.

Sometimes, an equation can be not exact, but it can be transformed into an exact one by multiplying the equation by the integrating factor.

So, `I(x,y)` is the integrating factor for the differential equation, if `I(x,y)(M(x,y)dx+N(x,y)dy)=0` is exact.

There are 2 conditions that allow to find the integrating factor easily:

If `1/N((partial M)/(partial y)-(partial N)/(partial x))=g(x)`, a function of `x` alone, then `I(x,y)=e^(int g(x)dx)`.

If `1/M((partial M)/(partial y)-(partial N)/(partial x))=h(y)`, a function of `x` alone, then `I(x,y)=e^(-int h(y)dy)`.

Now, let's do some more work with another example

**Example 3.** Solve `(y+1)dx-xdy=0`.

Here, `M(x,y)=y+1`, and `N(x,y)=-x`. Since `(partial M)/(partial y)=1` and `(partial N)/(partial x)=-1`, we have that `(partial M)/(partial y)!=(partial N)/(partial x)` and the equation is not exact. However, note that `1/N((partial M)/(partial y)-(partial N)/(partial x))=1/(-x)(1-(-1))=-2/x=g(x)`.

So, `I(x,y)=e^(int -2/xdx)=e^(-2ln(x))=1/x^2`.

Multiplying the differential equation by the integrating factor gives: `(y+1)/x^2dx-1/xdy=0`.

This equation is exact; so, there exists a function `f` such that `df=(y+1)/x^2 dx-1/x dy`. Using the fact that `(partial f)/(partial x)=(y+1)/x^2`, we find that `f=int (y+1)/x^2 dx=-(y+1)/x+g(y)`. Now, differentiating with respect to `y` gives: `(partial f)/(partial y)=-1/x+g'(y)`. On the other hand, `(partial f)/(partial y)=-1/x`; so, `-1/x+g'(y)=-1/x`, or `g'(y)=0`.

Solving it, we obtain that `g(y)=C_1`.

So, `f(x,y)=-(y+1)/x+g(y)=-(y+1)/x+C_1`.

Therefore, the solution is `-(y+1)/x+C_1=C`, or `y=c_2 x-1`, where `c_2=C_1-C`.

Let's solve another equation.

**Example 4.** Solve `2xydx+y^2dy=0`.

Here, `M(x,y)=2xy`, and `N(x,y)=y^2`. Since `(partial M)/(partial y)=2x` and `(partial N)/(partial x)=0`, we have that `(partial M)/(partial y)!=(partial N)/(partial x)` and the differential equation is not exact.

However, note that `1/M((partial M)/(partial y)=(partial N)/(partial x))=1/(2xy)(2x-0)=1/y=h(y)`.

So, the integrating factor is `I(x,y)=e^(-int 1/y dy)=e^(-ln(y))=1/y`.

Multiplying the differential equation by the integrating factor yields `1/y(2xydx+y^2dy)=0`, or `2xdx+ydy=0`.

This equation is exact. Using the fact that `(partial f)/(partial x)=2x`, we have that `f=int (2x)dx=x^2+h(y)`. Differentiating the last eqaution with respect to `y` gives: `(partial f)/(partial y)=h'(y)`.

On the other hand, `(partial f)/(partial y)=y`; so, `h'(y)=y`, or `h(y)=int ydy=1/2 y^2+c_1`.

So, `f=x^2+h(y)=x^2+1/2 y^2+c_1`, and the solution is ` x^2+1/2 y^2+c_1=C`, or `x^2+1/2 y^2=c_2` where `c_2=C-c_1`.

Another case when there can be easily found integrating factor is case when `M=yf(xy)` and `N=xg(xy)`. In this case `I(x,y)=1/(xM-yN)`.

**Example 5.** Solve `y(1-xy)dx+xdy=0`.

The equation is not exact; however, note that `M(x,y)` is in the form `y(1-xy)` and `N(x,y)=x*1`; so, the integrating factor is `I(x,y)=1/(xy(1-xy)-xy)=-1/(xy)^2`. Multiplying by `I(x,y)` yields:

`(xy-1)/(x^2y)dx-1/(xy^2)dy=0`. This equation is exact.

Using the fact that `(partial f)/(partial x)=(xy-1)/(x^2y)`, we have that `f=int ((xy-1)/(x^2 y))dx=ln(|x|)+1/(xy)+g(y)`.

Differentiating with respect to y gives: `(partial f)/(partial y)=-1/(xy^2)+g'(y)`. On the other hand, `(partial f)/(partial y)=-1/(xy^2)`.

So, `g'(y)=0` or `g(y)=c_1`.

Thus, `f(x,y)=ln(|x|)+1/(xy)+c_1`.

Finally, the solution is `ln(|x|)+1/(xy)+c_1=C`, or `ln(|x|)+1/(xy)=c_2`, where `c_2=C-c_1`.

Below is the list of common integrating factors:

Group of terms | `I(x,y)` | Exact differential `dg(x,y)` |

`ydx-xdy` | `-1/x^2` | `-(ydx-xdy)/x^2=d(y/x)` |

`ydx-xdy` | `1/y^2` | `(ydx-xdy)/y^2=d(x/y)` |

`ydx-xdy` | `-1/(xy)` | `-(ydx-xdy)/(xy)=d(ln(y/x))` |

`ydx-xdy` | `-1/(x^2+y^2)` | `-(ydx-xdy)/(x^2+y^2)=d(arctan(y/x))` |

`ydy+xdx` | `1/(xy)` | `(ydy+xdx)/(xy)=d(ln(xy))` |

`ydy+xdx` | `1/(xy)^n,n>1` | `(ydy+xdx)/(xy)^n=-d(1/((n-1)(xy)^(n-1)))` |

`ydy+xdx` | `1/(x^2+y^2)` | `(ydy+xdx)/(x^2+y^2)=d(1/2 ln(x^2+y^2))` |

`ydy+xdx` | `1/(x^2+y^2)^n, n>1` | `(ydy+xdx)/(x^2+y^2)^n=-d(1/(2(n-1)(x^2+y^2)^(n-1)))` |

`aydx+bxdy` (`a` and `b` constants) | `x^(a-1)y^(b-1)` | `x^(a-1)y^(b-1)(aydx+bxdy)=d(x^ay^b)` |

In general, integrating factors are difficult to uncover. If a differential equation doesn't have one of the forms given above, then searching for the integrating factor will likely be unsuccessful, and one should resort to other solution methods.