Two fields. One has a hidden hill behind it.

Here are two plane vector fields. They look roughly the same - swirly arrows, no obvious peak. But one of them is secretly the gradient of some scalar function $f$, and the other isn't. If we could recover that $f$, we'd know the work along any curve just from the endpoints. So: which is which, and how do we tell?

Field A

$\mathbf{u} = 2xy\,\mathbf{i} + (x^2 + 1)\,\mathbf{j}$
 

Field B

$\mathbf{u} = -y\,\mathbf{i} + x\,\mathbf{j}$
 

Given a vector field, can we always recover a scalar function it came from? And if we can, how do we actually find it?

This is exactly what physicists do every time they recover a gravitational potential from a force field, or an electric potential from $\mathbf{E}$. The recipe is general; the physics is just the most-used special case.

Step 0 - the two-step diagnostic

Before we integrate anything, we should ask whether a potential is even possible. There's a quick local test, and a global one. Both have to pass.

Step 0a - check the curl

We met the curl test back in §3.5; here's why we re-run it before integrating anything. A potential exists only if $\nabla \times \mathbf{u} = \mathbf{0}$, and if the test fails the integration we're about to set up is doomed before it starts.

In 2D we had one equation: $P_y = Q_x$. How many should we expect in 3D, and why? Roughly speaking, we need every pair of mixed partials to agree, and there are three pairs in three dimensions: $(L, M)$, $(L, N)$, $(M, N)$. So three equations.

$$\text{2D:}\quad \frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y} = 0.$$ $$\text{3D for } \mathbf{u} = L\,\mathbf{i} + M\,\mathbf{j} + N\,\mathbf{k}: \quad \frac{\partial M}{\partial z} = \frac{\partial N}{\partial y}, \quad \frac{\partial N}{\partial x} = \frac{\partial L}{\partial z}, \quad \frac{\partial L}{\partial y} = \frac{\partial M}{\partial x}.$$

If any cross-partial fails, stop. There is no $f$ - the integration we're about to set up is doomed, and forging ahead just produces inconsistent equations.

Step 0b - check the domain

Curl-zero is necessary but not quite sufficient. The four theorems of §5.6 tell us what's actually needed: a curl-zero field on a simply connected domain has a global potential. On a domain with holes, we may only get a local one.

For the rest of this page we'll assume Step 0 has passed: curl is zero, domain is simply connected. Now we go hunting for $f$.

Step 1 Integrate $P$ in $x$

We want $\nabla f = \mathbf{u}$, which means $f_x = P$, $f_y = Q$, $f_z = R$ all simultaneously. Pick the $x$-equation first and integrate it, treating $y$ and $z$ as parameters.

$$f(x, y, z) = \int P(x, y, z)\,dx + g(y, z).$$

The "$+\,g$" is the constant of integration with respect to $x$ - but it turns out that "constant" is a slippery word here.

The integration "constant" is a function of the uneliminated variables, not just a single number $C$. In 2D it's $g(y)$; in 3D it's $g(y, z)$. Forgetting to keep $g$ as a function of the remaining variables is the most common mistake at this step - and it silently kills the recipe, because we'll need $g_y$ and $g_z$ to be nonzero in the next steps to absorb $Q$ and $R$.

So at the end of Step 1 we have a candidate $f$ that's correct in $x$ by construction, but with an unknown function $g(y, z)$ riding along. The remaining equations $f_y = Q$ and $f_z = R$ will pin $g$ down.

Step 2 Match $Q$ to determine $g_y$

Differentiate the candidate $f$ from Step 1 with respect to $y$:

$$f_y \;=\; \frac{\partial}{\partial y} \int P(x, y, z)\,dx \;+\; g_y(y, z).$$

We need $f_y = Q$. Set the two expressions equal and solve for $g_y$:

$$g_y(y, z) \;=\; Q(x, y, z) \;-\; \frac{\partial}{\partial y} \int P(x, y, z)\,dx.$$

Sanity check. Look at the right-hand side. It seems to depend on $x$. But $g_y$ should be a function of $y$ and $z$ only - $x$ has no business being there. So every $x$ on the right must cancel.

Why does it cancel? Because the cross-partial condition $\partial L/\partial y = \partial M/\partial x$ from Step 0 guarantees it. It turns out that's exactly what the curl-zero test is doing for us here - paying off in the algebra. If you do the algebra and $x$ doesn't cancel, two things are possible: an arithmetic slip somewhere, or the field wasn't conservative to begin with (Step 0 was botched). Either way, stop and recheck.

Quick sanity check on $P = 2xy$, $Q = x^2$. After integrating $P$ in $x$, we get $f = x^2 y + g(y)$. Then $f_y = x^2 + g'(y)$. Set equal to $Q = x^2$. The $x^2$ cancels - leaving $g'(y) = 0$ - and the field is conservative. ✓ If the $x^2$ hadn't cancelled, we'd have hit a contradiction and known to abort.

Once $g_y$ is in hand, integrate in $y$:

$$g(y, z) \;=\; \int g_y(y, z)\,dy \;+\; h(z).$$

Same trap as before: the new integration "constant" $h$ is a function of the one variable we still haven't pinned down, namely $z$. In 2D the recipe ends here ($h$ collapses to a literal constant $C$). In 3D we have one more equation to use.

Step 3 Match $R$ to determine $h'(z)$ (3D only)

We now have a candidate $f(x, y, z)$ that's correct in $x$ and $y$, with one loose end: an unknown $h(z)$. Differentiate in $z$ and demand $f_z = R$:

$$h'(z) \;=\; R(x, y, z) \;-\; \frac{\partial}{\partial z}\!\left[\int P\,dx + \int g_y\,dy\right].$$

Same sanity check as Step 2, basically. The right-hand side looks like it could depend on $x$ and $y$, but it can't - $h$ is a function of $z$ alone. The other two curl-zero conditions, $\partial N/\partial x = \partial L/\partial z$ and $\partial M/\partial z = \partial N/\partial y$, are exactly what guarantees the $x$ and $y$ dependence cancels. If they don't cancel, the field isn't conservative or the algebra is off.

Integrate to get $h(z) + C$, where now $C$ is a genuine constant. Plug everything back in to assemble the final $f$.

Step 4 - always recompute $\nabla f$

The recipe has three integrations and three differentiations woven together. There are a lot of places to drop a sign or miscarry a $2$. Every time we finish, we go back and verify - not by re-reading the work, but by computing $\nabla f$ from scratch and comparing with $\mathbf{u}$.

$$\text{Take final } f. \quad \text{Compute } f_x, f_y, f_z. \quad \text{Confirm } (f_x, f_y, f_z) = (P, Q, R).$$

This is cheap (three differentiations, no integration) and catches just about every mistake the recipe is prone to: dropped terms, sign errors, forgotten coefficients.

Always verify. It catches sign errors and dropped terms in seconds. Skipping costs you points. We'll do it on the worked example next.

Recipe at a glance

  1. Step 0. Check curl is zero and the domain is simply connected.
  2. Step 1. $f = \int P\,dx + g(y, z)$.
  3. Step 2. Set $f_y = Q$, solve for $g_y$, integrate to get $g(y, z) = \int g_y\,dy + h(z)$.
  4. Step 3 (3D). Set $f_z = R$, solve for $h'(z)$, integrate to get $h(z) + C$.
  5. Step 4. Verify $\nabla f = \mathbf{u}$ component-by-component.

Worked example - a 3D field

Let's run the whole recipe on a clean 3D example. Take

$$\mathbf{u} \;=\; (2xy - z^2)\,\mathbf{i} \;+\; (x^2 + 2z)\,\mathbf{j} \;+\; (2y - 2xz)\,\mathbf{k}.$$

So $L = 2xy - z^2$, $M = x^2 + 2z$, $N = 2y - 2xz$. We're hunting for $f$ with $\nabla f = \mathbf{u}$.

Step 0 Curl check

Compute the three cross-partials.

$$\frac{\partial M}{\partial z} = 2, \quad \frac{\partial N}{\partial y} = 2 \;\;\checkmark$$ $$\frac{\partial N}{\partial x} = -2z, \quad \frac{\partial L}{\partial z} = -2z \;\;\checkmark$$ $$\frac{\partial L}{\partial y} = 2x, \quad \frac{\partial M}{\partial x} = 2x \;\;\checkmark$$

All three match. Curl is zero on $\mathbb{R}^3$, which is simply connected, so a global potential exists.

Step 1 Integrate $L$ in $x$

$$f(x, y, z) \;=\; \int (2xy - z^2)\,dx + g(y, z) \;=\; x^2 y - x z^2 + g(y, z).$$

Step 2 Match $M$, find $g_y$

Differentiate in $y$:

$$f_y \;=\; x^2 + g_y(y, z).$$

We need $f_y = M = x^2 + 2z$. So

$$g_y(y, z) \;=\; (x^2 + 2z) - x^2 \;=\; 2z.$$

Sanity check: $g_y$ has no $x$ in it. Good. Integrate in $y$:

$$g(y, z) \;=\; \int 2z\,dy + h(z) \;=\; 2yz + h(z).$$

So our updated candidate is

$$f(x, y, z) \;=\; x^2 y - x z^2 + 2yz + h(z).$$

Step 3 Match $N$, find $h'(z)$

Differentiate in $z$:

$$f_z \;=\; -2xz + 2y + h'(z).$$

We need $f_z = N = 2y - 2xz$. So

$$h'(z) \;=\; (2y - 2xz) - (-2xz + 2y) \;=\; 0.$$

Sanity check: $h'(z)$ has no $x$ or $y$ - in fact it's identically zero, which is allowed. Integrating gives $h(z) = C$, a genuine constant.

Final answer

$$\boxed{\,f(x, y, z) \;=\; x^2 y - x z^2 + 2yz + C.\,}$$

Step 4 Verify $\nabla f = \mathbf{u}$

Compute each partial from scratch and compare to the original components $L, M, N$.

$f_x = 2xy - z^2$vs.$L = 2xy - z^2$
$f_y = x^2 + 2z$vs.$M = x^2 + 2z$
$f_z = -2xz + 2y$vs.$N = 2y - 2xz$

All three components match. The potential is correct.

Edge case - curl zero, but no global potential

The recipe assumes Step 0b passes: the domain is simply connected. What if it isn't? The classic example is the planar vortex

$$\mathbf{u} \;=\; \frac{-y}{x^2 + y^2}\,\mathbf{i} + \frac{x}{x^2 + y^2}\,\mathbf{j}, \qquad D = \mathbb{R}^2 \setminus \{(0,0)\}.$$

A direct computation gives $Q_x - P_y = 0$ everywhere $\mathbf{u}$ is defined - so locally the recipe should work. What do you think $\oint \mathbf{u} \cdot d\mathbf{r}$ around the unit circle gives? Zero - since the curl is zero? Let's compute, and you'll see why we keep flagging the simply-connected hypothesis. But $D$ has a hole at the origin; it isn't simply connected. And indeed: the line integral of $\mathbf{u}$ around the unit circle gives $2\pi$, not zero. So no single-valued $f$ exists on all of $D$.

This same multi-valued behaviour is the reason magnetic potentials around a current-carrying wire are not single-valued - and why Ampère's law is genuinely about integrating around the wire, not about a global potential.

What still works: pick any simply connected sub-region of $D$ (a slit plane $\{x > 0\}$, or any open disc not containing the origin), and run the recipe there. You'll recover $f = \arctan(y/x) + C$ on the slit plane, $f = \theta$ in polar terms - exactly the angle function. Globally on $D$, $\theta$ is multi-valued: it jumps by $2\pi$ each time you loop the origin.

Multi-valued potentials are a real, useful object - not a failure mode. See §5.7 for how to use them: pick a system of "fundamental periods" (one per hole), and any line integral on $D$ becomes (single-valued part of $f$) + (integer combination of periods).

Practice Problems - §3.6 / §5.6

5(a) Find all $f$ with $\nabla f = \mathbf{v}$ for $\mathbf{v} = 2xyz\,\mathbf{i} + x^2 z\,\mathbf{j} + x^2 y\,\mathbf{k}$. (Kaplan §3.6)
For $\mathbf{v} = 2xyz\,\mathbf{i} + x^2 z\,\mathbf{j} + x^2 y\,\mathbf{k}$, verify that $\operatorname{curl} \mathbf{v} = \mathbf{0}$ and find every scalar function $f$ such that $\nabla f = \mathbf{v}$.
Step 0 - curl check. $\partial M/\partial z = x^2$, $\partial N/\partial y = x^2$ ✓. $\partial N/\partial x = 2xy$, $\partial L/\partial z = 2xy$ ✓. $\partial L/\partial y = 2xz$, $\partial M/\partial x = 2xz$ ✓. Curl is zero on $\mathbb{R}^3$, which is simply connected.
Step 1. $f = \int 2xyz\,dx + g(y, z) = x^2 yz + g(y, z)$.
Step 2. $f_y = x^2 z + g_y$. Set $= x^2 z$. So $g_y = 0$, hence $g(y, z) = h(z)$.
Step 3. $f_z = x^2 y + h'(z)$. Set $= x^2 y$. So $h'(z) = 0$, hence $h(z) = C$.
Final. $f = x^2 yz + C$. Verify: $f_x = 2xyz$ ✓, $f_y = x^2 z$ ✓, $f_z = x^2 y$ ✓.
5(b) Find all $f$ with $\nabla f = \mathbf{v}$ for $\mathbf{v} = e^{xy}\big[(2y^2 + yz^2)\mathbf{i} + (2xy + xz^2 + 2)\mathbf{j} + 2z\,\mathbf{k}\big]$. (Kaplan §3.6)
For $\mathbf{v} = e^{xy}\big[(2y^2 + yz^2)\mathbf{i} + (2xy + xz^2 + 2)\mathbf{j} + 2z\,\mathbf{k}\big]$ (Kaplan writes the $\mathbf{k}$ component without the $e^{xy}$ factor; we keep his convention $\mathbf{v} = e^{xy}[(\cdots)\mathbf{i} + (\cdots)\mathbf{j} + 2z\,\mathbf{k}]$ as printed), verify $\operatorname{curl} \mathbf{v} = \mathbf{0}$ and find all $f$ with $\nabla f = \mathbf{v}$.
Step 0. The cross-partials all match (long but mechanical - distribute $e^{xy}$ and use $\partial e^{xy}/\partial x = y e^{xy}$, $\partial e^{xy}/\partial y = x e^{xy}$). Domain is $\mathbb{R}^3$, simply connected.
Step 1. Try the ansatz $f = e^{xy} \cdot \phi(x, y, z) + g(y, z)$. Computing $f_x$ should give $e^{xy}(2y^2 + yz^2)$, which suggests $\phi = y \cdot \text{something}$. A direct integration: $\int e^{xy}(2y^2 + yz^2)\,dx = e^{xy}(2y + z^2)$ (since $y$ is constant in $x$, $\int e^{xy}\,dx = e^{xy}/y$, multiplied by $y(2y + z^2)$). So $f = e^{xy}(2y + z^2) + g(y, z)$.
Step 2. $f_y = x e^{xy}(2y + z^2) + e^{xy} \cdot 2 + g_y = e^{xy}(2xy + xz^2 + 2) + g_y$. Set $= e^{xy}(2xy + xz^2 + 2)$, so $g_y = 0$, hence $g(y, z) = h(z)$.
Step 3. $f_z = e^{xy} \cdot 2z + h'(z) = 2z e^{xy} + h'(z)$. Set $= 2z e^{xy}$ (the $\mathbf{k}$ component, with the $e^{xy}$ factor restored). So $h'(z) = 0$, hence $h(z) = C$.
Final. $f = e^{xy}(2y + z^2) + C$. Verify by computing $f_x, f_y, f_z$ and checking against the components of $\mathbf{v}$.
1(a) Determine $F(x, y)$ with $dF = 2xy\,dx + x^2\,dy$, then evaluate $\int_C dF$ along $C: y = x^3$ from $(0,0)$ to $(2, 8)$. (Kaplan after §5.6)
Determine by inspection a function $F(x, y)$ whose differential is $2xy\,dx + x^2\,dy$, and integrate $\displaystyle \int_C 2xy\,dx + x^2\,dy$ along $C: y = x^3$ from $(0, 0)$ to $(2, 8)$.
Step 0. $P = 2xy$, $Q = x^2$. $\partial Q/\partial x = 2x$, $\partial P/\partial y = 2x$ ✓. The plane is simply connected.
Step 1. $F = \int 2xy\,dx + g(y) = x^2 y + g(y)$.
Step 2. $F_y = x^2 + g'(y)$. Set $= x^2$, so $g'(y) = 0$ and $g(y) = C$. So $F(x, y) = x^2 y + C$. (This is what "by inspection" means - both terms come from differentiating $x^2 y$.)
Evaluate the line integral. Since the integrand is $dF$ and the field is conservative, $\int_C dF = F(2, 8) - F(0, 0) = 4 \cdot 8 - 0 = 32$. The path $y = x^3$ never enters the calculation - that's the payoff of finding the potential.
6(a) Show $\displaystyle \int_{(0,0)}^{(1,1)} 2xy\,dx + (x^2 - y^2)\,dy$ is path independent and evaluate. (Kaplan after §5.6)
Show that $\displaystyle \int_{(0,0)}^{(1,1)} 2xy\,dx + (x^2 - y^2)\,dy$ is independent of path in the $xy$-plane and evaluate it.
Step 0. $P = 2xy$, $Q = x^2 - y^2$. $\partial Q/\partial x = 2x$, $\partial P/\partial y = 2x$ ✓. The plane is simply connected, so a global potential exists and the integral is path independent.
Step 1. $F = \int 2xy\,dx + g(y) = x^2 y + g(y)$.
Step 2. $F_y = x^2 + g'(y)$. Set $= x^2 - y^2$, so $g'(y) = -y^2$ and $g(y) = -y^3/3 + C$. Hence $F(x, y) = x^2 y - y^3/3 + C$.
Evaluate. $\int_{(0,0)}^{(1,1)} dF = F(1, 1) - F(0, 0) = (1 - 1/3) - 0 = 2/3$.
Verify. $F_x = 2xy$ ✓, $F_y = x^2 - y^2$ ✓.