Exact Equations
Some first-order equations are secretly the statement "a certain function stays constant along the solution". If you can find that , the solutions are its level curves . 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
If there is a function with and , then along a solution , by the chain rule,
so . The function is a potential for the vector field .
The test
For smooth and on a rectangle (or any simply connected region), a potential exists exactly when
Necessity is equality of mixed partials: .
Finding the potential
Example. .
- Test: and . Exact.
- Integrate in : , where the "constant" may depend on .
- Differentiate in and match : , so and .
- Solutions: .
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 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.
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 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 . If depends only on , then works; symmetrically, if depends only on , use . The integrating factor for linear equations is the special case , .
Example. has . Here , so : is exact with .
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 exact? If so, find .
Answer
Yes; .
Solution
. ; , so .
Exercise 2: Not exact
Show that is not exact, and find an integrating factor depending only on .
Answer
.
Solution
, . depends only on , so . Then is exact with , so .
Exercise 3: Initial condition (code)
Find the solution of the lesson's example through and evaluate at .
Answer
The level curve is , but the solution never reaches : it ends near , where and the slope becomes vertical.
Solution
. At : , i.e. , which has no real root. So the solution through never reaches : hits zero first and the slope becomes infinite.
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
is exact on a rectangle when…
The solutions of an exact equation are…
- the level curves of the potential
- straight lines
- the gradient lines of
- always explicit functions
After integrating with respect to , the constant of integration…
- is a number
- may depend on
- may depend on
- is always zero