4. Exact equations

📖 Reading · 9 min
💡 Every code box below is live — edit it and hit Run.

§13.1 and §13.2 handled equations shaped like a product or a linear sum. This lesson handles a third family — and it turns out to be nothing more than §12.3's conservative vector fields, seen from a different angle. An "exact" differential equation is a conservative field in disguise, and solving it is finding the same potential function §12.0 and §12.3 already knew how to find.

Writing an equation in differential form

Any first-order equation can be written as

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

by moving everything to one side and treating dx,dy as differentials (the same notational move §13.1 used to separate variables). This is precisely §12.2's line-integral notation, P\,dx+Q\,dy, with M,N playing the roles of P,Q.

The exactness condition

The equation is called exact if M\,dx+N\,dy is literally the total differential of some function F(x,y) (§10.3's total differential, recalled): dF=F_x\,dx+F_y\,dy, so M=F_x and N=F_y. By Clairaut's theorem (§10.2), F_{xy}=F_{yx} whenever both are continuous, giving the exactness test:

\boxed{\frac{\partial M}{\partial y}=\frac{\partial N}{\partial x}}

This is word-for-word §12.3's conservative-field test, P_y=Q_x, applied to M,N instead of P,Q. An exact differential equation and a conservative vector field are the same mathematical object — $\langle M,N\rangle$ passing the test means it's a gradient field, and F is exactly its potential function.

Solving an exact equation

If the equation is exact, M\,dx+N\,dy=dF for some F, so the equation M\,dx+N\,dy=0 becomes dF=0 — meaning F(x,y) stays constant along any solution curve. The (implicit) general solution is simply:

F(x,y)=C

Finding F uses the identical integrate-then-match procedure from §12.0 and §12.3: integrate M with respect to x (holding y constant) to get F up to an unknown function of y; differentiate that candidate with respect to y, match against N, and solve for the missing piece.

No new technique is being introduced in this lesson at all — every step below is a direct relabeling of §12.3's potential-function method, applied to a differential equation instead of a work-computation problem.

Doing it in Python

Solving (2xy+3)\,dx+(x^2-1)\,dy=0 by checking exactness and finding the potential function — identical code to §12.3's worked example, with different variable names for the roles of P,Q:

import sympy as sp

x, y = sp.symbols('x y')
M, N = 2*x*y + 3, x**2 - 1

M_y = sp.diff(M, y)
N_x = sp.diff(N, x)
print(f"M_y = {M_y}, N_x = {N_x}, exact: {M_y == N_x}")

F = sp.integrate(M, x)
g_prime = sp.simplify(N - sp.diff(F, y))
g = sp.integrate(g_prime, y)
potential = F + g
print(f"F(x,y) = {potential}")
print(f"implicit solution: {potential} = C")

Confirming the solution by checking dF=M\,dx+N\,dy directly:

import sympy as sp

x, y = sp.symbols('x y')
F = x**2*y + 3*x - y

F_x, F_y = sp.diff(F, x), sp.diff(F, y)
print(f"F_x = {F_x}   (should match M = 2xy+3)")
print(f"F_y = {F_y}   (should match N = x^2-1)")

A non-exact equation, confirming the test correctly rejects it:

import sympy as sp

x, y = sp.symbols('x y')
M, N = y**2, x   # a candidate that is NOT exact

M_y = sp.diff(M, y)
N_x = sp.diff(N, x)
print(f"M_y = {M_y}, N_x = {N_x}, exact: {M_y == N_x}")
print("this equation needs a different technique -- separable, linear, or an integrating factor")

Worked example

Solve (2xy+3)\,dx+(x^2-1)\,dy=0.

Check exactness: M=2xy+3\Rightarrow M_y=2x. $N=x^2-1\Rightarrow N_x=2x$.

M_y=N_x=2x\ \Longrightarrow\ \boxed{\text{exact}}

Find F: integrate M with respect to x:

F(x,y)=\int(2xy+3)\,dx=x^2y+3x+g(y)

Differentiate with respect to y and match against N:

F_y=x^2+g'(y)\overset!=x^2-1\ \Longrightarrow\ g'(y)=-1\ \Longrightarrow\ g(y)=-y

F(x,y)=x^2y+3x-y

\boxed{x^2y+3x-y=C}

Sanity check. Differentiate the implicit solution with respect to x (treating y=y(x), §10.4's implicit differentiation): $F_x+F_y\cdot y'=0\Rightarrow(2xy+3)+(x^2-1)y'=0$ — rearranging, (x^2-1)y'=-(2xy+3), which is exactly the original equation written as y'=-\frac{2xy+3}{x^2-1}, i.e. M+Ny'=0, i.e. M\,dx+N\,dy=0. The implicit solution reproduces the original differential equation exactly under implicit differentiation — a strong structural confirmation. ✓

Your turn

1. Check whether (3x^2+2y)\,dx+(2x+3y^2)\,dy=0 is exact.

2. If the equation in problem 1 is exact, find its implicit general solution F(x,y)=C.

3. True or false: every exact equation is also separable.

Solutions

1. M=3x^2+2y\Rightarrow M_y=2. N=2x+3y^2\Rightarrow N_x=2.

M_y=N_x=2\ \Longrightarrow\ \boxed{\text{exact}}

2. F(x,y)=\int(3x^2+2y)\,dx=x^3+2xy+g(y).

Match: $F_y=2x+g'(y)\overset!=2x+3y^2\Rightarrow g'(y)=3y^2\Rightarrow g(y)=y^3$.

F(x,y)=x^3+2xy+y^3

\boxed{x^3+2xy+y^3=C}

3. False. §13.0's own worked-example equation, y'=x+y, written in differential form as (x+y)\,dx-dy=0 (so M=x+y, N=-1), has M_y=1 but N_x=0not exact. And separately, this equation is already known (§13.1) to not be separable either. Being exact and being separable are two genuinely different properties a first-order equation can independently have, share, or lack entirely — the three techniques across §13.1–§13.3 cover different, overlapping (but not identical) families of equations.

Check yourself in code

Check whether (2xy+3)\,dx+(x^2-1)\,dy=0 is exact and, if so, find its potential function F(x,y).

Print exactly this:

exact: True
F(x,y) = x**2*y + 3*x - y
import sympy as sp

x, y = sp.symbols('x y')
M, N = 2*x*y + 3, x**2 - 1

M_y = sp.diff(M, y)
N_x = sp.diff(N, x)
print("exact: ...")

F = sp.integrate(M, x)
g_prime = sp.simplify(N - sp.diff(F, y))
g = sp.integrate(g_prime, y)
potential = F + g
print("F(x,y) = ...")
import sympy as sp

x, y = sp.symbols('x y')
M, N = 2*x*y + 3, x**2 - 1

M_y = sp.diff(M, y)
N_x = sp.diff(N, x)
print(f"exact: {M_y == N_x}")

F = sp.integrate(M, x)
g_prime = sp.simplify(N - sp.diff(F, y))
g = sp.integrate(g_prime, y)
potential = F + g
print(f"F(x,y) = {potential}")

An exact equation, M\,dx+N\,dy=0 with M_y=N_x, is precisely a conservative vector field written as a differential equation — the same test, the same potential-function-finding procedure, and the same Clairaut's-theorem justification as §12.3, simply relabeled. Once found, the potential function F(x,y)=C is the implicit general solution, since the original equation says nothing more than "F stays constant." Separable, linear, and exact are three genuinely different (and only partially overlapping) families — most first-order equations belong to at most one of them, and recognizing which is the main skill this trio of lessons builds.

Next: turning these solving techniques toward real phenomena — population growth, radioactive decay, the logistic model, and Newton's law of cooling.