[Math] Recover scalar field from gradient

multivariable-calculuspartial derivativescalar-fieldsvector analysis

In one dimension, if I have a Riemann-integrable derivative $f'$ of a function $f$ which I don't know, I can (almost) recover $f$ from integrating $f'$.

A simple example would be $f'(x)=2x$, then by the Fundamental Theorem of Calculus, I get that $f(x)=x^2 + const,$ where the constant does not depend on $x$. I said 'almost recover' because to determine the constant, we need a point on the graph of $f$.

My question is now: Is it possible to recover a scalar field $f:\mathbb{R}^n \rightarrow \mathbb{R}$ when I only know the gradient $\left( \partial_1 f(x), \ldots, \partial_n f(x) \right)$.

My thoughts: I could apply the fundamental theorem of calculus in the first component by integrating over $x_1$, but then, I would get
\begin{align}
\int \partial_1 f(x)d x_1=f(x)+C,
\end{align}
where $C$ constant only in $x_1$, but may well vary with $x_2,\ldots,x_n$. I write $C=C_{-1}$ to indicate this. I could now proceed and do the same calculation for all the partial derivatives, i.e.
\begin{align}
\int \partial_i f(x)d x_i=f(x)+C_{-i}.
\end{align}
I cannot just add them together and divide by $n$ to recover $f$ plus a constant (in all variables). In fact, adding any two distinct $C_{-i}$ and $C_{-j}$ together woud give me a function depending on all $x_i$'s.

I thought about considering $f(x)+C_{-1}=f(x)+C_{-2}$ where $f$ would cancel. Because the left hand side does not depend on $x_1$ and the right hand side does not depend on $x_2$, neither side depends on either $x_1$ or $x_2$. It appears to me that this shows that the $C_{-i}$ all are constants in all $x_i$'s, but it cannot be correct, as the follwing example shows: Take $f(x_1,x_2)=x_1+x_2$. Then
\begin{align}
\left( \partial_1 f,\partial_2 f \right)=(1,1)
\end{align}
If now $C_{-1}$ would indeed be a constant, I would have
\begin{align}
f(x)=\int \partial_1 f(x)dx_1=x_1+c
\end{align}
which is wrong. I've looked around and found the Gradient Theorem which appears to be the right statement, but I don't see how to use it to find $f$, probably because I don't know much about line integrals.

Best Answer

Method 1: Use the fundamental theorem of calculus for line integrals, which tells you that you have $f(y)-f(x)=\int_C \nabla f \cdot d\mathrm{r}$ where $C$ is any path from $x$ to $y$.

Method 2: integrate in one variable, differentiate in another variable, set the result equal to the given partial derivative of $f$. This means you write

$$f(\mathrm{x})=\int \frac{\partial f}{\partial x_i} dx_i = g_i(\mathrm{x})+h_i(x_1,\dots,x_{i-1},x_{i+1},\dots,x_n).$$

This $g_i$ falls out of the integration, while $h_i$ is the "constant of integration". Differentiate this with respect to $x_j$ and set the result equal to $\frac{\partial f}{\partial x_j}$. Integrate again, repeat until you've gone through all the variables.

Method 3: Integrate each of the partial derivatives and then just evaluate the "constant of integration" by inspection. For example:

$$\frac{\partial f}{\partial x}=x+y \\ \frac{\partial f}{\partial y}=x+\cos(y)$$

then $f(x,y)=x^2/2+xy+h_1(y),f(x,y)=xy+\sin(y)+h_2(x)$, so "by inspection" $h_1(y)=\sin(y),h_2(x)=x^2/2$.

Related Question