Learning Objectives
After this section you should be able to:
- Recognize a first-order ODE written in differential form and decide whether it is exact.
- Explain why the test is the right test, in terms of Clairaut's theorem on mixed partial derivatives.
- Solve an exact equation by constructing the potential function and writing .
- Visualize the solution as a family of level curves of , with the vector as the gradient pointing across them.
- Repair a non-exact equation with an integrating factor, and verify everything in Python with SymPy and PyTorch.
The Big Picture: Walking on Level Curves
Imagine you are standing on a hillside. The height at each point is given by some function . If you want to walk so your altitude never changes, you are forced to walk along a level curve .
At any point on that curve, the direction you must step in satisfies one condition: the total change in height must be zero. Using the chain rule, a tiny step changes F by , so “height does not change” becomes:
If we set and , this is exactly the differential form . So the question “is this ODE exact?” is the same as the question “is the left-hand side the differential of some height function F?”
The one-line idea
An ODE is exact when its left-hand side is the total differential of some function F. The solution is then simply — the level curves of that hidden potential.
Where the Idea Comes From
Almost every first-order ODE of the form can be rewritten in differential form by clearing the fraction:
For some choices of M and N, the left-hand side is the perfect differential of a height function F. When that happens we are extremely lucky — we can integrate the equation in one swoop without any tricks. This is why exact equations are usually the first “easy case” after separable equations: the equation has already done the work of telling us what its own conserved quantity is.
Definition: Exact Differential Equation
Let M and N be continuous on an open rectangle . The first-order differential equation
is called exact on R if there exists a continuously differentiable function such that
In that case is called a potential for the equation, and the general solution is the family of level curves
The Test for Exactness
How do we know whether the F we are hoping for exists, without already knowing F? Answer: we use one of the cleanest theorems in multivariable calculus.
Clairaut's theorem. If F has continuous second partials, then . Mixed partials commute.
Apply Clairaut to our hoped-for potential F. We assumed and . Differentiate the first identity with respect to y and the second with respect to x:
Clairaut says these two right-hand sides are equal. So if F exists, then . The converse also holds on a simply-connected region. We get the clean test:
Test for exactness
That is one line of partial differentiation. If it agrees, you can always construct F; if it disagrees, no F exists and we need a different technique (an integrating factor, a substitution, etc.).
Interactive: Vector Fields and Level Curves
The picture below makes the “walking on level curves” intuition concrete. The yellow arrows are the vector field ; when the equation is exact these are the gradient . The blue curves are the level curves — i.e. the solutions. Switch between the presets and watch how the arrows always sit perpendicular to the solution curves.
Solving an Exact Equation (Four Steps)
Once we know the equation is exact, recovering F is a small piece of calculus. We will derive the method here so that nothing feels like a recipe.
- Step 1. Since we want , integrate M with respect to x, treating y as a constant:The “constant of integration” is allowed to depend on , because anything that vanishes when you differentiate with respect to x — including a function of y alone — is a legal piece of F. Hence .
- Step 2. The other constraint is . Differentiate the F you just built with respect to y:Solve this equation for . Here is the crucial point: because the equation is exact, every on the right-hand side cancels and you are left with an expression in only. That is the algebraic shadow of .
- Step 3. Integrate in y to obtain . There is one additive constant, which we absorb into later.
- Step 4. Assemble F and write the implicit solution:If an initial condition is given, evaluate F at that point to pin down .
Worked Example (Try by Hand)
Let's solve a representative problem completely. The example is chosen so that everything — test, integration, an cancellation, an initial condition — appears in one go. Work it out yourself first, then expand the panel to compare.
Problem. Solve subject to .
Show the full hand-worked solution
Interactive: Step-by-Step Solver
Pick a problem and reveal the steps one at a time. Try Problem 3 first — it is intentionally non-exact, and seeing how the procedure breaks down is the cleanest way to feel why we need the test.
When It Is Not Exact: Integrating Factors
Most ODEs you run into in the wild fail the exactness test. The repair strategy is to multiply both sides by a function chosen so that the new equation
becomes exact. is called an integrating factor. The exactness condition for the multiplied equation is , which expands to
In full generality that is itself a PDE in . Two special cases solve cleanly:
| Situation | Integrating factor |
|---|---|
| (M_y − N_x) / N depends only on x | μ(x) = exp ∫ (M_y − N_x)/N dx |
| (N_x − M_y) / M depends only on y | μ(y) = exp ∫ (N_x − M_y)/M dy |
Notice that this generalizes the integrating-factor trick you already saw for first-order linear ODEs in Section 1: the linear case is just the special case where .
Python: Verify Exactness Symbolically
Doing the bookkeeping by hand is great for understanding, but SymPy can run the whole pipeline — test, integrate, assemble — in eight short lines. Read each card before running it. The explanations describe what every single line is doing, why it is needed, and what value the line produces on the running example.
M_y = 2*x N_x = 2*x Exact? True Implicit solution: F(x, y) = x**2*y + 3*x + 2*y**2 = C
PyTorch: Mixed Partials by Autograd
Once you have F in hand, the test is just Clairaut's theorem applied to F. The same engine that trains neural networks can be asked to differentiate F twice, in either order, and confirm the two answers numerically match. Doing this gives you a feel for autograd as a generic “numerical chain-rule machine,” which is exactly what backpropagation is.
M = dF/dx = 7.0 N = dF/dy = 9.0 dM/dy = 2.0 dN/dx = 2.0 Exact? True
Applications
Conservative Force Fields in Physics
A force is conservative precisely when the work form is exact. The potential energy U with is exactly the F we have been building, up to a sign. Closed-loop work is zero because .
Thermodynamic State Functions
In thermodynamics, internal energy U, entropy S, enthalpy H, and Gibbs energy G are state functions: their differentials are exact. The first law is an exact form, which is why mixed Maxwell relations like hold. Heat and work , on the other hand, are not exact — they are path-dependent.
Electrostatics
For a static electric field , the relation says precisely that is exact. The potential is the F of this section.
Machine Learning
A loss function is automatically a potential for its gradient field , so gradient descent is the discretization of the exact equation with a sign flip. When you train a model, you are flowing along the gradient of an exact form. The Hessian symmetry condition you see in second-order optimizers (Newton, L-BFGS) is the very same Clairaut identity.
Common Pitfalls
- Mixing up M and N. M is the coefficient of dx, N is the coefficient of dy. Test against , not the other way around.
- Forgetting g(y) in Step 1. When integrating M with respect to x, the constant of integration must be allowed to depend on y. If you drop it, you will be unable to satisfy .
- Forgetting to re-test after multiplying by μ. An integrating factor is a guess — verify the multiplied equation is now exact before integrating it.
- Hidden domain issues. The theorem “exactness ⇔ mixed partials agree” needs a simply-connected region. On a punctured plane (e.g. dropping the origin), an ODE can locally look exact and still fail to have a single-valued potential — this is the same obstruction that makes the differential form locally but not globally exact.
- Plugging into the wrong equation. When you apply an initial condition, plug it into , not into the original differential form — the original form is zero at every point on a solution and tells you nothing about C.
Summary
| Concept | What to remember |
|---|---|
| Differential form | M(x,y) dx + N(x,y) dy = 0 packages an ODE without dividing by anything |
| Exact | There exists F with ∂F/∂x = M and ∂F/∂y = N. Solutions are F(x,y) = C. |
| Test | ∂M/∂y = ∂N/∂x (Clairaut) |
| Method | F = ∫M dx + g(y); fix g(y) from ∂F/∂y = N; write F = C. |
| Geometry | (M, N) is ∇F. The solution curves are the level curves of F, always perpendicular to (M, N). |
| Not exact? | Multiply by an integrating factor μ(x) or μ(y) and re-test. |
| Cross-check | SymPy verifies M_y vs N_x symbolically; PyTorch autograd does it numerically by double-differentiating F. |
Coming next: in Section 21.3 we will tackle ODEs that are neither linear nor exact, using clever substitutions (Bernoulli, homogeneous, and others) to reduce them to one of the two cases we now know how to solve.