Exact Differential Equations

An exact differential equation has the form M(x, y) dx + N(x, y) dy = 0 with ∂M/∂y = ∂N/∂x. Then there is a potential function ψ(x, y) with ψₓ = M and ψᵧ = N, and the solutions are the curves ψ(x, y) = C. You find ψ by integrating M with respect to x and matching N.

Before this lesson: First-Order Linear Differential Equations, Partial Derivatives and Conservative Vector Fields

The idea: solutions are level curves

Suppose a function ψ(x, y) stays constant along a solution curve, so ψ(x, y) = C. Differentiating both sides with respect to x, with y a function of x, gives ψₓ + ψᵧ · dy/dx = 0 by the multivariable chain rule. In differential form, that is ψₓ dx + ψᵧ dy = 0.

So an equation M dx + N dy = 0 is easy to solve whenever M and N are the two partial derivatives of one function ψ. The solutions are simply the level curves ψ(x, y) = C. Such an equation is called exact, and ψ is called a potential function.

How can you tell without knowing ψ? If M = ψₓ and N = ψᵧ, then Mᵧ = ψₓᵧ and Nₓ = ψᵧₓ, and those mixed partials are equal for smooth functions. This is the same test that tells whether the vector field ⟨M, N⟩ is conservative.

Exact differential equations: the test and the method

M(x, y)\,dx + N(x, y)\,dy = 0 \text{ is exact } \iff \dfrac{\partial M}{\partial y} = \dfrac{\partial N}{\partial x}

The test holds on a rectangle (or any region without holes) where M, N and their first partial derivatives are continuous.

  1. Write the equation as M dx + N dy = 0. If it is given as dy/dx = f(x, y), multiply through by dx and move every term to one side.
  2. Test for exactness: compute Mᵧ and Nₓ and check that they are equal.
  3. Integrate M with respect to x, treating y as a constant: ψ = ∫M dx + h(y). The constant of integration can depend on y, so write it as h(y).
  4. Differentiate that ψ with respect to y and set it equal to N. Solve for h′(y). It must not contain x.
  5. Integrate h′(y) to get h(y). No constant is needed here.
  6. Write the general solution ψ(x, y) = C, and use an initial condition to find C.

You can also start by integrating N with respect to y and matching M. Pick whichever integral is easier.

Exact differential equations examples

Example 1: Test and solve

Solve (2xy + 3) dx + (x² + 4y) dy = 0.

M = 2xy + 3,\; N = x^2 + 4y

Identify M and N.

M_y = 2x

Differentiate M with respect to y, holding x fixed (see partial derivatives).

N_x = 2x

Differentiate N with respect to x, holding y fixed.

M_y = N_x

They match, so the equation is exact.

\psi = \int (2xy + 3)\,dx = x^2y + 3x + h(y)

Integrate M with respect to x. The constant can depend on y, so call it h(y).

\psi_y = x^2 + h'(y)

Differentiate ψ with respect to y.

x^2 + h'(y) = x^2 + 4y

Set ψᵧ equal to N.

h'(y) = 4y

Subtract x² from both sides.

h(y) = 2y^2

Integrate with respect to y.

x^2y + 3x + 2y^2 = C

Write ψ(x, y) = C.

Answer: x²y + 3x + 2y² = C. This is an implicit solution; implicit differentiation of it gives back the original equation.

Example 2: An initial-value problem

Solve (y cos x + 2x) dx + (sin x + 3y²) dy = 0 with y(0) = 2.

M_y = \cos x,\; N_x = \cos x

M = y cos x + 2x and N = sin x + 3y². The partials match, so the equation is exact.

\psi = \int (y\cos x + 2x)\,dx = y\sin x + x^2 + h(y)

Integrate M with respect to x.

\psi_y = \sin x + h'(y)

Differentiate with respect to y.

h'(y) = 3y^2

Set ψᵧ equal to N = sin x + 3y² and subtract sin x.

h(y) = y^3

Integrate with respect to y.

y\sin x + x^2 + y^3 = C

Write the general solution.

2\sin 0 + 0^2 + 2^3 = C

Substitute x = 0 and y = 2.

C = 8

Since sin 0 = 0 and 2³ = 8.

Answer: y sin x + x² + y³ = 8.

Example 3: Not exact? Use an integrating factor

Solve (3xy + y²) dx + (x² + xy) dy = 0 for positive x.

M_y = 3x + 2y,\; N_x = 2x + y

Compute both partials. They are different, so the equation is not exact.

\dfrac{M_y - N_x}{N} = \dfrac{x + y}{x(x + y)}

Subtract the partials and factor x out of N (see factoring out the GCF).

\dfrac{M_y - N_x}{N} = \dfrac{1}{x}

Cancel x + y. The result depends on x alone, so an integrating factor μ(x) exists.

\mu = e^{\int (1/x)\,dx} = x

Find the integrating factor, as in first-order linear equations.

(3x^2y + xy^2)\,dx + (x^3 + x^2y)\,dy = 0

Multiply every term by x.

M_y = 3x^2 + 2xy = N_x

Test again: now the equation is exact.

\psi = x^3y + \tfrac{1}{2}x^2y^2 + h(y)

Integrate the new M with respect to x.

\psi_y = x^3 + x^2y + h'(y)

Differentiate with respect to y.

h'(y) = 0

Set ψᵧ equal to the new N = x³ + x²y and subtract.

x^3y + \tfrac{1}{2}x^2y^2 = C

h is a constant, so it joins C.

Answer: x³y + ½x²y² = C. The rule used here: if (Mᵧ − Nₓ)/N depends only on x, then μ(x) = e^(∫(Mᵧ − Nₓ)/N dx) makes the equation exact.

Example 4: Starting from dy/dx

Solve dy/dx = −(2x + ye^(xy))/(2y + xe^(xy)).

(2x + ye^{xy})\,dx + (2y + xe^{xy})\,dy = 0

Multiply both sides by (2y + xe^(xy)) dx and move every term to the left.

M_y = e^{xy} + xye^{xy}

Differentiate ye^(xy) with respect to y using the product rule.

N_x = e^{xy} + xye^{xy}

Differentiate xe^(xy) with respect to x the same way. The partials match: exact.

\psi = x^2 + e^{xy} + h(y)

Integrate M with respect to x. With y held fixed, the integral of ye^(xy) dx is e^(xy).

\psi_y = xe^{xy} + h'(y)

Differentiate with respect to y.

h'(y) = 2y

Set ψᵧ equal to N = 2y + xe^(xy) and subtract xe^(xy).

h(y) = y^2

Integrate with respect to y.

x^2 + y^2 + e^{xy} = C

Write ψ(x, y) = C.

Answer: x² + y² + e^(xy) = C.

Example 5: Streamlines of a water flow (word problem)

Water flows across a shallow pool. At the point (x, y), in meters, its velocity has components u = x + 2y and v = 4x − y (in cm/s). A drop of dye placed at (2, 1) drifts along a streamline, a curve whose slope at each point is dy/dx = v/u. Find the equation of the dye’s path.

\dfrac{dy}{dx} = \dfrac{4x - y}{x + 2y}

Write the slope of a streamline, v/u.

(4x - y)\,dx - (x + 2y)\,dy = 0

Cross-multiply and move every term to the left.

M_y = -1,\; N_x = -1

M = 4x − y and N = −x − 2y. The partials match: exact.

\psi = 2x^2 - xy + h(y)

Integrate M with respect to x.

\psi_y = -x + h'(y)

Differentiate with respect to y.

h'(y) = -2y

Set ψᵧ equal to N = −x − 2y and add x to both sides.

h(y) = -y^2

Integrate with respect to y.

2x^2 - xy - y^2 = C

The streamlines are the level curves of ψ.

2(2)^2 - (2)(1) - (1)^2 = C

Substitute the starting point (2, 1).

C = 5

Simplify: 8 − 2 − 1 = 5.

Answer: the dye follows 2x² − xy − y² = 5. The equation came out exact because this flow neither compresses nor expands: uₓ + vᵧ = 1 + (−1) = 0.

Coordinate grid with x from −7 to 7 and y from −4 to 4. Streamlines are the level curves 2x² − xy − y² = C. The streamline 2x² − xy − y² = 5 is drawn as a thick curve with two branches, one on the right and one on the left. It passes through the dye's starting point (2, 1), where an arrow shows the velocity (4, 7) pointing up and to the right. Thin curves show the streamlines for C = −5 and C = 15, and dashed lines show C = 0, the lines y = x and y = −2x. A key below the graph names each curve.
Each streamline is a level curve of ψ = 2x² − xy − y². The dye starting at (2, 1) stays on the curve where ψ = 5.

Common mistakes

MistakeExample of the errorFix
Testing the wrong partialsComparing M_x with N_yCompare M_y (M with respect to y) with N_x (N with respect to x).
Using a plain constant instead of h(y)Writing \psi = x^2y + 3x + C after integrating MWhen you integrate with respect to x, the constant can depend on y: write h(y).
Adding both integrals\psi = (x^2y + 3x) + (x^2y + 2y^2)Shared terms like x^2y appear in both integrals. Count each term once.
Losing a sign when rewriting dy/dxFrom \frac{dy}{dx} = \frac{4x - y}{x + 2y}, taking N = x + 2yMove every term to one side: N = −(x + 2y).
Keeping an x in h′(y)Getting h'(y) = 4y + x and integrating anywayh′ can’t depend on x. Recheck the test or the algebra.
Stopping at ψGiving x^2y + 3x + 2y^2 as the answerThe solution is the equation ψ(x, y) = C.

Related methods

Conservative vector fields

The test Mᵧ = Nₓ is the same test used for conservative vector fields, and ψ is the potential function of the field ⟨M, N⟩. Finding ψ works exactly the same way in both settings.

Integrating factors for equations that aren’t exact

If this depends on one variableUse this integrating factor
\dfrac{M_y - N_x}{N} depends on x only\mu(x) = e^{\int \frac{M_y - N_x}{N}\,dx}
\dfrac{N_x - M_y}{M} depends on y only\mu(y) = e^{\int \frac{N_x - M_y}{M}\,dy}

Every first-order linear equation y′ + p(x)y = q(x) becomes exact after you multiply by e^(∫p dx), which is why the integrating factor method works.

Separable equations

A separable differential equation dy/dx = g(x)h(y) can be written g(x) dx − (1/h(y)) dy = 0. Here Mᵧ = 0 and Nₓ = 0, so every separable equation is exact.

Practice problems

  1. Show that (2x + y) dx + (x + 6y) dy = 0 is exact and solve it.
  2. Solve (3x² + 2y) dx + (2x − 4y³) dy = 0.
  3. Is x²y dx + xy² dy = 0 exact?
  4. Solve (eˣ + y) dx + (x + 2y) dy = 0 with y(0) = 1.
  5. Solve (2xy³ + cos x) dx + (3x²y² − 1) dy = 0.
  6. Solve (y/x + 6x) dx + (ln x − 2) dy = 0 for positive x.
  7. Solve dy/dx = −(2xy + 1)/(x² + 3y²).
  8. Solve (4x³ + 2y) dx + (2x + 2y) dy = 0 with y(1) = 2.
  9. Find an integrating factor that makes (2y² + 3x) dx + 2xy dy = 0 exact (for positive x), then solve it.
  10. A flow has velocity components u = 2x + y and v = 3x − 2y. Find the streamline through (1, 1), using dy/dx = v/u.
Show answers

1.

M_y = 1,\; N_x = 1

M = 2x + y and N = x + 6y. The partials match: exact.

\psi = x^2 + xy + h(y)

Integrate M with respect to x.

x + h'(y) = x + 6y

Set ψᵧ equal to N.

h'(y) = 6y

Subtract x from both sides.

h(y) = 3y^2

Integrate with respect to y.

Answer: x² + xy + 3y² = C

2.

M_y = 2,\; N_x = 2

M = 3x² + 2y and N = 2x − 4y³: exact.

\psi = x^3 + 2xy + h(y)

Integrate M with respect to x.

2x + h'(y) = 2x - 4y^3

Set ψᵧ equal to N.

h'(y) = -4y^3

Subtract 2x from both sides.

h(y) = -y^4

Integrate with respect to y.

Answer: x³ + 2xy − y⁴ = C

3.

M_y = x^2

M = x²y, so its partial with respect to y is x².

N_x = y^2

N = xy², so its partial with respect to x is y².

x^2 \ne y^2

The partials are different functions.

Answer: not exact

4.

M_y = 1,\; N_x = 1

M = eˣ + y and N = x + 2y: exact.

\psi = e^x + xy + h(y)

Integrate M with respect to x.

h'(y) = 2y

Set x + h′(y) equal to N and subtract x.

e^x + xy + y^2 = C

Integrate h′ to get h = y² and write ψ = C.

e^0 + 0 + 1^2 = C

Substitute x = 0 and y = 1.

C = 2

Simplify: 1 + 0 + 1.

Answer: eˣ + xy + y² = 2

5.

M_y = 6xy^2,\; N_x = 6xy^2

Differentiate 2xy³ + cos x with respect to y and 3x²y² − 1 with respect to x: exact.

\psi = x^2y^3 + \sin x + h(y)

Integrate M with respect to x.

3x^2y^2 + h'(y) = 3x^2y^2 - 1

Set ψᵧ equal to N.

h'(y) = -1

Subtract 3x²y² from both sides.

h(y) = -y

Integrate with respect to y.

Answer: x²y³ + sin x − y = C

6.

M_y = \dfrac{1}{x},\; N_x = \dfrac{1}{x}

M = y/x + 6x and N = ln x − 2: exact.

\psi = y\ln x + 3x^2 + h(y)

Integrate M with respect to x (x is positive).

\ln x + h'(y) = \ln x - 2

Set ψᵧ equal to N.

h'(y) = -2

Subtract ln x from both sides.

h(y) = -2y

Integrate with respect to y.

Answer: y ln x + 3x² − 2y = C

7.

(2xy + 1)\,dx + (x^2 + 3y^2)\,dy = 0

Multiply by (x² + 3y²) dx and move every term to the left.

M_y = 2x,\; N_x = 2x

The partials match: exact.

\psi = x^2y + x + h(y)

Integrate M with respect to x.

h'(y) = 3y^2

Set x² + h′(y) equal to N and subtract x².

h(y) = y^3

Integrate with respect to y.

Answer: x²y + x + y³ = C

8.

M_y = 2,\; N_x = 2

M = 4x³ + 2y and N = 2x + 2y: exact.

\psi = x^4 + 2xy + h(y)

Integrate M with respect to x.

h'(y) = 2y

Set 2x + h′(y) equal to N and subtract 2x.

x^4 + 2xy + y^2 = C

Integrate h′ to get h = y² and write ψ = C.

1 + 2(1)(2) + 2^2 = C

Substitute x = 1 and y = 2.

C = 9

Simplify: 1 + 4 + 4.

Answer: x⁴ + 2xy + y² = 9

9.

M_y = 4y,\; N_x = 2y

M = 2y² + 3x and N = 2xy. Different, so not exact.

\dfrac{M_y - N_x}{N} = \dfrac{2y}{2xy} = \dfrac{1}{x}

Depends on x only.

\mu = e^{\int (1/x)\,dx} = x

Find the integrating factor.

(2xy^2 + 3x^2)\,dx + 2x^2y\,dy = 0

Multiply every term by x.

M_y = 4xy = N_x

Now exact.

\psi = x^2y^2 + x^3 + h(y)

Integrate the new M with respect to x.

h'(y) = 0

ψᵧ = 2x²y + h′(y) must equal N = 2x²y.

Answer: μ = x, and x²y² + x³ = C

10.

(3x - 2y)\,dx - (2x + y)\,dy = 0

Write dy/dx = (3x − 2y)/(2x + y), cross-multiply and move every term to the left.

M_y = -2,\; N_x = -2

M = 3x − 2y and N = −2x − y: exact.

\psi = \tfrac{3}{2}x^2 - 2xy + h(y)

Integrate M with respect to x.

h'(y) = -y

Set −2x + h′(y) equal to N and add 2x.

\tfrac{3}{2}x^2 - 2xy - \tfrac{1}{2}y^2 = C

Integrate h′ to get h = −y²/2.

3x^2 - 4xy - y^2 = K

Multiply both sides by 2 and call 2C = K.

3 - 4 - 1 = K

Substitute x = 1 and y = 1.

Answer: 3x² − 4xy − y² = −2

Exact differential equations FAQ

What makes a differential equation exact?

An equation M dx + N dy = 0 is exact when M and N are the partial derivatives ψₓ and ψᵧ of one function ψ. You test it by checking that ∂M/∂y = ∂N/∂x.

How do you find the potential function?

Integrate M with respect to x and add an unknown h(y). Differentiate the result with respect to y, set it equal to N, solve for h′(y), and integrate. The solution is ψ(x, y) = C.

What if the equation is not exact?

Look for an integrating factor. If (Mᵧ − Nₓ)/N depends only on x, or (Nₓ − Mᵧ)/M depends only on y, the formulas above give one. Otherwise try another method, such as a substitution.

Is every separable equation exact?

Yes. Written as g(x) dx − (1/h(y)) dy = 0, it has Mᵧ = 0 and Nₓ = 0. Both methods give the same solution.

Summary

  • M dx + N dy = 0 is exact when Mᵧ = Nₓ.
  • Then M = ψₓ and N = ψᵧ for a potential function ψ.
  • Find ψ: integrate M with respect to x, add h(y), and match ψᵧ to N.
  • The general solution is ψ(x, y) = C, usually in implicit form.
  • If the test fails, an integrating factor μ(x) or μ(y) may make the equation exact.

Previous lesson: First-Order Linear Differential Equations

Next lesson: Bernoulli Equations

Back to the Differential Equations Index