Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 39 ยท First-order ODEs

Exact Equations and Integrating Factors for Exactness

Recognize exact ODEs M dx + N dy = 0 with the partial-derivative test, find the potential function, and rescue non-exact equations with integrating factors, using SymPy.

Some first-order equations are really the statement that a certain function of two variables stays constant along the solution. If you can spot that function, the solution is just a level curve. Such equations are called exact. They appear when you write a first-order ODE in the differential form

M(x, y) dx + N(x, y) dy = 0,

and they connect differential equations to the multivariable calculus idea of a conservative field and its potential function.

The idea

Suppose there is a function F(x, y) with F_x = M and F_y = N. Then along any curve y = y(x) the chain rule gives dF/dx = F_x + F_y*y' = M + N*y'. If the ODE says M + N*y' = 0, then dF/dx = 0, hence F(x, y) = c is the implicit general solution.

So the question becomes: when does such an F exist? A necessary and sufficient condition (on a simply connected region) comes from equality of mixed partials, F_xy = F_yx:

dM/dy = dN/dx.

This is the exactness test.

The method

  1. Write the equation as M dx + N dy = 0.
  2. Test: is M_y = N_x? If not, it is not exact (see below).
  3. Integrate M with respect to x: F = integral of M dx + h(y), where h(y) is an unknown function of y only.
  4. Differentiate this F with respect to y and set it equal to N; solve for h'(y). All x terms must cancel (they do when the test passed).
  5. Integrate h' to get h(y). The solution is F(x, y) = c.

Worked example

(2*x*y + 3) dx + (x**2 + 4*y) dy = 0. Here M_y = 2*x, N_x = 2*x: exact. Integrate M in x: F = x**2*y + 3*x + h(y). Then F_y = x**2 + h'(y) must equal N = x**2 + 4*y, so h' = 4*y, h = 2*y**2. The solution: x**2*y + 3*x + 2*y**2 = c.

Python Exactness test and potential function

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Using an initial condition

For y(0) = 1 in the example: 0 + 0 + 2 = c, so c = 2 and the particular solution is x**2*y + 3*x + 2*y**2 = 2. This is quadratic in y, so you can solve it explicitly: 2*y**2 + x**2*y + (3*x - 2) = 0 gives y = (-x**2 + sqrt(x**4 - 8*(3*x - 2)))/4, picking the sign that passes through (0, 1).

Python Follow the level curve numerically

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The solution stops near x = 0.67, where x**2 + 4*y = 0 and the tangent becomes vertical, so the run covers 0 <= x <= 0.6. The invariant F stays at 2 along the numerical solution: that is the whole meaning of exactness.

When the equation is not exact

Take y dx + (x**2*y - x) dy = 0: M_y = 1, N_x = 2*x*y - 1; not equal. Sometimes multiplying by an integrating factor mu makes it exact. There are two easy cases.

  • If (M_y - N_x)/N depends only on x, then mu(x) = exp(integral of (M_y - N_x)/N dx).
  • If (N_x - M_y)/M depends only on y, then mu(y) = exp(integral of (N_x - M_y)/M dy).

In the example, (N_x - M_y)/M = (2*x*y - 2)/y: not only y. And (M_y - N_x)/N = (2 - 2*x*y)/(x*(x*y - 1)) = -2/x, which depends only on x. So mu = exp(-2 ln x) = x**(-2). Multiply through: (y/x**2) dx + (y - 1/x) dy = 0. Now M_y = 1/x**2 and N_x = 1/x**2: exact. Integrating gives F = -y/x + y**2/2, and the solution is -y/x + y**2/2 = c.

Python Find the integrating factor with SymPy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Relationship to other methods

Every separable equation g(x) dx + h(y) dy = 0 is exact (M_y = 0 = N_x), and every linear equation becomes exact after multiplying by its integrating factor, as in the previous lesson. Exactness is the common thread: you are always looking for a function constant along solutions. For equations that fit none of these patterns, try substitutions.

The potential F can be found only on a region without holes. For (-y dx + x dy)/(x**2 + y**2) = 0 the test M_y = N_x passes everywhere except the origin, yet F = arctan(y/x) is multi-valued on circles around it. Check where your solution is valid.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the exactness test for M dx + N dy = 0?

    If a potential F exists with F_x = M and F_y = N, mixed partials agree, giving M_y = N_x.
  2. 2. For (2xy + 3) dx + (x**2 + 4y) dy = 0, the first step of finding F is

    F = integral of M dx + h(y), then match F_y to N to find h.
  3. 3. An exact equation's solution is given implicitly by

    Because dF/dx = 0 along solutions, F stays constant on each solution curve.
  4. 4. If (M_y - N_x)/N depends only on x, the integrating factor is

    That formula makes the product muM, muN satisfy the exactness test.

Summary

  • Write M dx + N dy = 0; it is exact when M_y = N_x.
  • Build F by integrating M in x, then fix h(y) using F_y = N.
  • The solution is the level curve F(x, y) = c.
  • Non-exact equations can sometimes be fixed by an integrating factor depending on x alone or y alone.
  • A conserved quantity along a numerical solution is an excellent check.

Next: Substitutions: Homogeneous and Bernoulli Equations