TExcelTAD
Home › Differential Equations › Exact Equations

Exact Equations

Some first-order equations are secretly the statement "a certain function F(x,y)F(x, y) stays constant along the solution". If you can find that FF, the solutions are its level curves F(x,y)=CF(x, y) = C. Such equations are called exact, and they connect differential equations to the gradients and potential functions of Calculus in Depth.

The idea

Write the equation in differential form

M(x,y) dx+N(x,y) dy=0,i.e.y′=−M(x,y)N(x,y).M(x, y)\,dx + N(x, y)\,dy = 0, \qquad\text{i.e.}\qquad y' = -\frac{M(x, y)}{N(x, y)}.

If there is a function FF with Fx=MF_x = M and Fy=NF_y = N, then along a solution y(x)y(x), by the chain rule,

ddxF(x,y(x))=Fx+Fy y′=M+Ny′=0,\frac{d}{dx}F(x, y(x)) = F_x + F_y\,y' = M + N y' = 0,

so F(x,y(x))=CF(x, y(x)) = C. The function FF is a potential for the vector field (M,N)(M, N).

The test

For smooth MM and NN on a rectangle (or any simply connected region), a potential exists exactly when

∂M∂y=∂N∂x.\frac{\partial M}{\partial y} = \frac{\partial N}{\partial x}.

Necessity is equality of mixed partials: Fxy=FyxF_{xy} = F_{yx}.

Finding the potential

Example. (2xy+3) dx+(x2+4y) dy=0(2xy + 3)\,dx + (x^2 + 4y)\,dy = 0.

  1. Test: My=2xM_y = 2x and Nx=2xN_x = 2x. Exact.
  2. Integrate MM in xx: F=x2y+3x+g(y)F = x^2y + 3x + g(y), where the "constant" may depend on yy.
  3. Differentiate in yy and match NN: Fy=x2+g′(y)=x2+4yF_y = x^2 + g'(y) = x^2 + 4y, so g′(y)=4yg'(y) = 4y and g=2y2g = 2y^2.
  4. Solutions: x2y+3x+2y2=Cx^2y + 3x + 2y^2 = C.
python · try it yourself
import sympy as sp

x, yv = sp.symbols("x y")
M = 2 * x * yv + 3
N = x**2 + 4 * yv
print("M_y = N_x ?", sp.diff(M, yv) == sp.diff(N, x))
F = sp.integrate(M, x)
F += sp.integrate(sp.simplify(N - sp.diff(F, yv)), yv)
print("F =", F)
M_y = N_x ? True
F = x**2*y + 3*x + 2*y**2

SymPy's dsolve recognises exact equations (hint 1st_exact) and returns the level set as an implicit equation or solves it for yy when it can.

Checking along a numerical solution

The potential is a conserved quantity: it must stay constant along any solution. That gives a strong check on a numerical solver.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

F = lambda x, y: x**2 * y + 3 * x + 2 * y**2
rhs = lambda x, y: -(2 * x * y + 3) / (x**2 + 4 * y)
sol = solve_ivp(rhs, (0, 0.6), [1.0], t_eval=np.linspace(0, 0.6, 4), rtol=1e-10, atol=1e-12)
for xv, yv in zip(sol.t, sol.y[0]):
    print(f"x = {xv:.2f}  y = {yv:.6f}  F = {F(xv, yv):.8f}")
x = 0.00  y = 1.000000  F = 2.00000000
x = 0.20  y = 0.826720  F = 2.00000000
x = 0.40  y = 0.593719  F = 2.00000000
x = 0.60  y = 0.238786  F = 2.00000000

We stop at x=0.6x = 0.6 because this solution cannot be continued much further (Exercise 3 shows why).

Integrating factors

An equation that is not exact can sometimes be made exact by multiplying by a factor μ\mu. If My−NxN\frac{M_y - N_x}{N} depends only on xx, then μ(x)=e∫My−NxNdx\mu(x) = e^{\int \frac{M_y - N_x}{N}dx} works; symmetrically, if Nx−MyM\frac{N_x - M_y}{M} depends only on yy, use μ(y)\mu(y). The integrating factor for linear equations is the special case M=py−qM = py - q, N=1N = 1.

Example. y dx+2x dy=0y\,dx + 2x\,dy = 0 has My=1≠Nx=2M_y = 1 \ne N_x = 2. Here Nx−MyM=1y\frac{N_x - M_y}{M} = \frac{1}{y}, so μ=y\mu = y: y2 dx+2xy dy=0y^2\,dx + 2xy\,dy = 0 is exact with F=xy2F = xy^2.

In software

  • Conserved quantities are used to validate simulations: energy in a frictionless physics simulation, total mass in a fluid solver. A drifting invariant points to a too-large time step or a bug.
  • Symplectic integrators used for orbits and molecular dynamics are designed to keep such invariants nearly constant for very long runs.

Exercises

Exercise 1: Test and solve

Is (3x2+y) dx+(x−2y) dy=0(3x^2 + y)\,dx + (x - 2y)\,dy = 0 exact? If so, find FF.

Answer

Yes; F=x3+xy−y2F = x^3 + xy - y^2.

Solution

My=1=NxM_y = 1 = N_x. F=∫(3x2+y) dx=x3+xy+g(y)F = \int (3x^2 + y)\,dx = x^3 + xy + g(y); Fy=x+g′=x−2yF_y = x + g' = x - 2y, so g=−y2g = -y^2.

Exercise 2: Not exact

Show that (x+y) dx−x dy=0(x + y)\,dx - x\,dy = 0 is not exact, and find an integrating factor depending only on xx.

Answer

μ=x−2\mu = x^{-2}.

Solution

My=1M_y = 1, Nx=−1N_x = -1. My−NxN=2−x\frac{M_y - N_x}{N} = \frac{2}{-x} depends only on xx, so μ=e∫−2/x dx=x−2\mu = e^{\int -2/x\,dx} = x^{-2}. Then (1x+yx2)dx−1xdy=0\left(\frac{1}{x} + \frac{y}{x^2}\right)dx - \frac{1}{x}dy = 0 is exact with F=ln⁡∣x∣−yxF = \ln\lvert x\rvert - \frac{y}{x}, so y=xln⁡∣x∣−Cxy = x\ln\lvert x\rvert - Cx.

Exercise 3: Initial condition (code)

Find the solution of the lesson's example through (0,1)(0, 1) and evaluate yy at x=1x = 1.

Answer

The level curve is x2y+3x+2y2=2x^2y + 3x + 2y^2 = 2, but the solution never reaches x=1x = 1: it ends near x≈0.675x \approx 0.675, where N=x2+4y=0N = x^2 + 4y = 0 and the slope becomes vertical.

Solution

C=F(0,1)=2C = F(0, 1) = 2. At x=1x = 1: y+3+2y2=2y + 3 + 2y^2 = 2, i.e. 2y2+y+1=02y^2 + y + 1 = 0, which has no real root. So the solution through (0,1)(0, 1) never reaches x=1x = 1: N=x2+4yN = x^2 + 4y hits zero first and the slope becomes infinite.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp
rhs = lambda x, y: -(2 * x * y + 3) / (x**2 + 4 * y)
stop = lambda x, y: x**2 + 4 * y[0]
stop.terminal = True
sol = solve_ivp(rhs, (0, 1), [1.0], events=stop, rtol=1e-10, atol=1e-12)
print(f"stopped near x = {sol.t[-1]:.4f}; roots of 2y^2 + y + 1:", np.roots([2, 1, 1]))
stopped near x = 0.6753; roots of 2y^2 + y + 1: [-0.25+0.66143783j -0.25-0.66143783j]

Test yourself

M dx+N dy=0M\,dx + N\,dy = 0 is exact on a rectangle when…

  1. M=NM = N
  2. Mx=NyM_x = N_y
  3. My=NxM_y = N_x
  4. My+Nx=0M_y + N_x = 0

The solutions of an exact equation are…

  1. the level curves F(x,y)=CF(x, y) = C of the potential
  2. straight lines
  3. the gradient lines of FF
  4. always explicit functions y(x)y(x)

After integrating MM with respect to xx, the constant of integration…

  1. is a number
  2. may depend on yy
  3. may depend on xx
  4. is always zero