Once a field passes the test for conservative fields, you can find a potential $f$ with $\nabla f = \mathbf{F}$ by integrating one variable at a time. The only subtle point is the "constant" of integration: when you integrate with respect to $x$, anything that does not depend on $x$ acts like a constant.
Key idea
To find $f$ with $\nabla f = \langle P, Q \rangle$:
- Integrate $P$ with respect to $x$: $f = \int P\,dx + g(y)$, where $g$ is an unknown function of $y$.
- Differentiate that with respect to $y$ and set it equal to $Q$. This gives $g'(y)$.
- Integrate to get $g(y)$ (up to a constant) and put it back. Check by computing $\nabla f$.
- In space, the unknown after the first step is $g(y, z)$; use $Q$ to find how it depends on $y$ (up to a function $h(z)$), then $R$ to find $h$.
Why it works
Why $g$ depends on $y$: $\frac{\partial}{\partial x} g(y) = 0$, so adding any function of $y$ does not change $f_x$.
Why step 2 always works for a conservative field: $g'(y) = Q - \frac{\partial}{\partial y}\int P\,dx$ must not depend on $x$. Its $x$-derivative is $Q_x - \frac{\partial}{\partial y}\frac{\partial}{\partial x}\int P\,dx = Q_x - P_y$, which is ${}0$ exactly when the field passes the test. If you ever find $x$ left in $g'(y)$, the field is not conservative (or there is an arithmetic slip).
Why step 2 always works for a conservative field: $g'(y) = Q - \frac{\partial}{\partial y}\int P\,dx$ must not depend on $x$. Its $x$-derivative is $Q_x - \frac{\partial}{\partial y}\frac{\partial}{\partial x}\int P\,dx = Q_x - P_y$, which is ${}0$ exactly when the field passes the test. If you ever find $x$ left in $g'(y)$, the field is not conservative (or there is an arithmetic slip).
Worked examples
Worked example: In the plane
Find a potential for $\mathbf{F} = \langle 2xy + 3, x^2 + 4y \rangle$.
- $$f = \int (2xy + 3)\,dx = x^2y + 3x + g(y).$$
- $f_y = x^2 + g'(y)$ must equal $x^2 + 4y$, so $g'(y) = 4y$ and $g(y) = 2y^2$.
- $f = x^2y + 3x + 2y^2$ (plus any constant). Check: $\nabla f = \langle 2xy + 3, x^2 + 4y \rangle$.
Answer: $x^2y + 3x + 2y^2 + C$
Worked example: With an exponential
Find a potential for $\mathbf{F} = \langle ye^{xy}, xe^{xy} + 2y \rangle$.
- $f = \int ye^{xy}\,dx = e^{xy} + g(y)$.
- $f_y = xe^{xy} + g'(y) = xe^{xy} + 2y$, so $g'(y) = 2y$, $g = y^2$.
- $f = e^{xy} + y^2$.
Answer: $e^{xy} + y^2 + C$
Worked example: In space
Find a potential for $\mathbf{F} = \langle 2x + yz, xz + z^2, xy + 2yz \rangle$.
- $$f = \int (2x + yz)\,dx = x^2 + xyz + g(y, z).$$
- $f_y = xz + g_y = xz + z^2$, so $g_y = z^2$ and $g = yz^2 + h(z)$.
- $f_z = xy + 2yz + h'(z) = xy + 2yz$, so $h' = 0$.
- $f = x^2 + xyz + yz^2$.
Answer: $x^2 + xyz + yz^2 + C$
Common mistake
Integrating each component and adding. In the first example, $\int P\,dx = x^2y + 3x$ and $\int Q\,dy = x^2y + 2y^2$. Adding them gives ${}2x^2y + 3x + 2y^2$, whose gradient is $\langle 4xy + 3, 2x^2 + 4y \rangle$, not $\mathbf{F}$: the shared term $x^2y$ was counted twice. A term that appears in several partial integrals belongs in $f$ once. Following the steps above, or checking $\nabla f$ at the end, catches this.