Exact First-Order Equations

Sometimes the expression M d x + N d y is the total differential of a single function f ( x , y ) . When that happens the equation M d x + N d y = 0 says simply d f = 0 , and the solution is f ( x , y ) = c . This section answers two questions: how to test whether an equation is of this type, and how to recover f when it is.

Quick Reference

Item Statement
Total differential d f = f x d x + f y d y
Exact equation M d x + N d y = 0 where M = f x and N = f y for some f
Test for exactness M y = N x , necessary and sufficient
General solution f ( x , y ) = c
Step 1 f ( x , y ) = M ( x , y ) d x + g ( y )
Step 2 Set f y = N and solve for g'(y)
Step 3 Integrate g'(y) and write f ( x , y ) = c
Alternative route Start from f y = N and integrate in y , with an "constant" h ( x )

Where Exact Equations Come From

We remember from calculus that if a function z = f ( x , y ) has continuous first partial derivatives, its total differential is defined by

dz = df = \frac{\partial f}{\partial x}\,dx + \frac{\partial f}{\partial y}\,dy . \tag{1}

Therefore, if a family of curves is described by f ( x , y ) = c , taking the differential of both sides gives

df = \frac{\partial f}{\partial x}\,dx + \frac{\partial f}{\partial y}\,dy = 0 . \tag{2}

Recall that the differential of a constant is zero, which is what makes the right-hand side vanish.

This is the same elimination of arbitrary constants met in Section 1.3, now viewed through differentials. Every one-parameter family f ( x , y ) = c produces a first-order differential equation, and equations produced this way are exactly the ones this section solves.

The family of curves x 3 y 2 = c satisfies a differential equation. Find it.

Solution

Take the differential of both sides:

x ( x 3 y 2 ) d x + y ( x 3 y 2 ) d y = 0

or

3 x 2 y 2 d x + 2 x 3 y d y = 0 .

Dividing both sides by 2 x 3 y d x , the equation can be rewritten as

3 x 2 y 2 2 x 3 y + d y d x = 0

or, simplifying the fraction,

\frac{dy}{dx} = -\frac{3y}{2x} \tag{3}

This is a differential equation, and we have arrived at it knowing its general solution in advance: the solution of (3) is x 3 y 2 = c .

Read backwards, this is the whole idea of the section. Had we been handed 3 x 2 y 2 d x + 2 x 3 y d y = 0 cold, the task would be to recognize the left-hand side as d ( x 3 y 2 ) and read off the answer.

Graph of the family of curves x cubed times y squared equals c, for several values of c.
Graph of x 3 y 2 = c for different values of c . Each curve is one integral curve of the equation d y d x = 3 y 2 x .

Definition of an Exact Equation

Now consider a differential equation written in the form

M(x,y)\,dx + N(x,y)\,dy = 0 \tag{4}

where M and N are assumed to have continuous first partial derivatives.

If there exists a function f ( x , y ) such that

\frac{\partial f}{\partial x} = M \quad\text{and}\quad \frac{\partial f}{\partial y} = N \tag{5}

then the differential form M d x + N d y is called an exact differential, and Equation (4) is called an exact differential equation.

In that case (4) can be rewritten as

f x d x + f y d y = 0 or d f = 0 ,

and the general solution of Equation (4) is

f ( x , y ) = c .

The solution f ( x , y ) = c is an implicit solution, in contrast with an explicit solution y = ϕ ( x ) .

The function f is sometimes called a potential function, by analogy with physics, where a conservative force field is the gradient of a potential and the level curves of that potential are the curves of constant energy.

Two questions now need answering: when is a differential equation exact, and if it is exact, how do we find its solution?

Test for Exactness

The equations (5) lead to

2 f y x = M y , and 2 f x y = N x .

From calculus we know that mixed partial derivatives are equal,

2 f y x = 2 f x y

provided these partial derivatives are continuous. This is Clairaut's theorem. Hence

M d x + N d y = 0    is exact M y = N x .

So the condition M / y = N / x is necessary for exactness. Conversely, it can be shown that this condition is also sufficient:

M y = N x M d x + N d y = 0    is exact.

Let M ( x , y ) and N ( x , y ) have continuous first partial derivatives on a rectangular region of the x y -plane. Then the equation M d x + N d y = 0 is exact if and only if

M y = N x .
Proof of sufficiency

To prove that M y = N x is sufficient for exactness, let

P ( x , y ) = M ( x , y ) d x ,

the partial integral of M with respect to x , holding y fixed. By construction,

P x = M ( x , y ) .

Differentiating both sides with respect to y ,

2 P y x = M y .

By hypothesis the right side equals N x , and by equality of mixed partials the left side equals 2 P x y . Therefore

N x = 2 P x y = x ( P y ) .

Both N and P y have the same partial derivative with respect to x , so they differ by at most a function of y alone:

N = P y + g ( y )

where g ( y ) is an arbitrary function of y . This function is our integration "constant", which must be allowed to depend on y because y was held fixed during the partial integration.

Consequently,

M d x + N d y = P x d x + P y d y + g ( y ) d y = d { P ( x , y ) + G ( y ) } ,

where G ( y ) is any antiderivative of g , so that d G ( y ) = g ( y ) d y .

We have shown that if M y = N x , then M d x + N d y is the differential of a function, namely P ( x , y ) + G ( y ) . That is precisely the statement that the equation is exact.

The proof is not merely an existence argument. It is a recipe: partially integrate M in x , then correct by a function of y alone. The method of solution below is exactly this proof carried out on a concrete equation.

Method of Solution

Now we find the general solution of M d x + N d y = 0 when the equation is exact. Let f ( x , y ) be a function whose differential is M d x + N d y .

Step 1. Because f x = M ,

f(x,y) = \int M(x,y)\,dx + g(y) \tag{6}

where g ( y ) is the "constant" of integration. Remember that if we differentiate (6) with respect to x , both g ( y ) and y behave as constants, so the term g ( y ) disappears and the identity f / x = M is restored regardless of what g is.

Step 2. Because f y = N , differentiate (6) with respect to y and set the result equal to N :

N = f y = y M ( x , y ) d x + d g ( y ) d y .

Therefore

d g ( y ) d y = N y M ( x , y ) d x

Step 3. Integrate both sides with respect to y :

g ( y ) = ( N y M ( x , y ) d x ) d y

Putting the pieces together,

f ( x , y ) = M ( x , y ) d x + ( N y M ( x , y ) d x ) d y g ( y )

and the general solution of the differential equation is f ( x , y ) = c , where c is an arbitrary constant.

Remark. The two variables play symmetric roles, so you may instead start from f y = N and integrate with respect to y while holding x fixed, introducing a "constant" h ( x ) . Choose whichever of M and N is easier to integrate.

Built-in check. In Step 2, the expression that remains for g'(y) must be free of x . If an x survives, either the equation was not exact or an algebra slip occurred. This makes Step 2 a free verification of Step 1.

Worked Examples

Find the general solution of the equation

( x 3 + y 2 + y ) d x + ( y 3 + 2 x y + x ) d y = 0 .
Solution

Here M = x 3 + y 2 + y and N = y 3 + 2 x y + x . Testing for exactness,

M y = 2 y + 1 , N x = 2 y + 1 ,

so M y = N x and the equation is exact.

Let d f = M d x + N d y . Because f x = M ,

\begin{aligned} f(x,y) &= \int M\,dx + g(y) \\ &= \int \left(x^3 + y^2 + y\right)dx + g(y) \\ &= \frac{x^4}{4} + y^2 x + yx + g(y) . \end{aligned}

Here y was treated as a constant throughout, so y 2 and y integrated to y 2 x and y x .

Now impose f y = N :

\begin{aligned} \frac{\partial}{\partial y}\left[\frac{x^4}{4} + y^2 x + yx + g(y)\right] &= y^3 + 2xy + x \\ 2yx + x + g'(y) &= y^3 + 2xy + x \\ g'(y) &= y^3 \end{aligned}

All the x terms cancelled, exactly as they must. Integrating,

g ( y ) = y 4 4 + c ,

and we may drop the constant c here, since a single arbitrary constant will appear at the end.

Thus

f ( x , y ) = x 4 4 + y 2 x + y x + y 4 4

and the general solution is

x 4 4 + y 2 x + y x + y 4 4 = C

where C is a constant determined from an initial condition. Multiplying by 4 gives the tidier form x 4 + 4 y 2 x + 4 y x + y 4 = 4 C .

Find the general solution of the equation e y d x + ( x e y + 2 y ) d y = 0 .

Solution

Here

M ( x , y ) = e y , N ( x , y ) = x e y + 2 y .

Because

M y = e y = N x ,

this equation is exact.

We are looking for f ( x , y ) such that

\left\{ \begin{aligned} \frac{\partial f}{\partial x} &= M(x,y) = e^{y}, \\[6pt] \frac{\partial f}{\partial y} &= N(x,y) = x e^{y} + 2y \end{aligned} \right.

Integrating the first equation with respect to x , treating y as constant,

f ( x , y ) = e y d x + g ( y ) = x e y + g ( y ) .

Therefore

\frac{\partial f}{\partial y} = x e^{y} + g'(y) .

This partial derivative must equal N ( x , y ) = x e y + 2 y :

x e^{y} + g'(y) = x e^{y} + 2y \quad \Longrightarrow \quad g'(y) = 2y \quad \Longrightarrow \quad g(y) = y^2 + c .

Finally

f ( x , y ) = x e y + y 2 + c = c 1 .

Combining the two constants, the solution is simply

x e y + y 2 = c 2 .

Solve the initial value problem ( 2 x + y ) d x + ( x 6 y ) d y = 0 , y ( 1 ) = 0 .

Solution

Here M = 2 x + y and N = x 6 y , with

M y = 1 = N x ,

so the equation is exact.

Integrating M with respect to x ,

f ( x , y ) = x 2 + x y + g ( y ) .

Differentiating with respect to y and matching N ,

x + g'(y) = x - 6y \quad \Longrightarrow \quad g'(y) = -6y \quad \Longrightarrow \quad g(y) = -3y^2 .

So the general solution is

x 2 + x y 3 y 2 = C .

Applying y ( 1 ) = 0 gives 1 + 0 0 = C , so C = 1 and the solution is

x 2 + x y 3 y 2 = 1 .

Exercises

Determine whether ( 3 x 2 y + 2 ) d x + ( x 3 + 4 y ) d y = 0 is exact, and solve it if it is.

Solution

With M = 3 x 2 y + 2 and N = x 3 + 4 y ,

M y = 3 x 2 = N x ,

so the equation is exact.

Integrating M in x : f = x 3 y + 2 x + g ( y ) . Then \dfrac{\partial f}{\partial y} = x^3 + g'(y), and matching N gives g'(y) = 4y, so g ( y ) = 2 y 2 .

The general solution is x 3 y + 2 x + 2 y 2 = C .

Show that y d x x d y = 0 is not exact, then verify that dividing by y 2 makes it exact and solve.

Solution

With M = y and N = x ,

M y = 1 , N x = 1 ,

which differ, so the equation is not exact.

Dividing by y 2 gives 1 y d x x y 2 d y = 0 . Now M = 1 y and N = x y 2 , and

M y = 1 y 2 = N x ,

so the new equation is exact. Integrating M in x gives f = x y + g ( y ) , and \dfrac{\partial f}{\partial y} = -\dfrac{x}{y^2} + g'(y) matches N with g'(y) = 0.

The solution is x y = C , that is, y = k x with k = 1 / C .

The factor 1 / y 2 used here is an integrating factor, the subject of the next section.

Solve ( cos y + 2 x ) d x ( x sin y ) d y = 0 .

Solution

With M = cos y + 2 x and N = x sin y ,

M y = sin y = N x ,

so the equation is exact.

Integrating M in x : f = x cos y + x 2 + g ( y ) . Then \dfrac{\partial f}{\partial y} = -x\sin y + g'(y), and matching N gives g'(y) = 0.

The general solution is x cos y + x 2 = C .

Frequently Asked Questions

What does "exact" actually mean?

It means the expression M d x + N d y is the total differential of some single function f ( x , y ) . The equation then reads d f = 0 , whose content is that f stays constant along solutions. Finding the solution amounts to identifying f , and the answer is the level-curve family f ( x , y ) = c .


Why does the test M / y = N / x work?

If the equation is exact then M = f x and N = f y , so M / y and N / x are the two mixed second partials of f . Clairaut's theorem says these are equal when continuous, which gives the necessity. Sufficiency requires the constructive argument in the proof above, and it needs the region to be a rectangle or otherwise simply connected.


Why is the constant of integration a function g ( y ) rather than a number?

Because the integration in Step 1 is partial, performed with respect to x while y is held fixed. Anything not depending on x differentiates to zero under / x , and that includes every function of y alone. So the most general "constant" available at that stage is g ( y ) .


What if an x is left over when I solve for g'(y)?

Then something is wrong. Either the equation is not exact, so recheck the test, or there is an algebra error in Step 1 or Step 2. Since g depends on y alone, g'(y) cannot contain x , which makes this a reliable self-check.


What do I do when the exactness test fails?

Look for an integrating factor, a function μ ( x , y ) such that multiplying through by it makes the equation exact. That is the subject of Section 2.5, and the second exercise above is a small preview of the idea.


Which variable should I integrate first?

Whichever of M and N is simpler to integrate. The two routes give the same answer. In the second worked example, integrating M = e y with respect to x was trivial, whereas starting from N = x e y + 2 y would have been more work for the same result.


Should I present the answer explicitly as y = ϕ ( x ) ?

Usually not. The natural form of the answer is the implicit relation f ( x , y ) = c , and solving for y is often impossible, as in x 4 + 4 y 2 x + 4 y x + y 4 = C . Leave it implicit unless the algebra untangles cleanly.