Is there a Lagrangian whose Euler-Lagrange equation is the gradient? I am trying to recast a problem I am working on in terms of Lagrangian mechanics.  I am in the following situation.  Suppose I have a function $f:X \rightarrow \mathbb{R}$ (a field).  In the its simplest case, I am studying constant functions. Since $X$ is an open ball, this is the same as studying:
$$ \nabla f = 0. $$ 
Embarrassing enough, I don't know how recast this simple differential equation in terms of Lagrangian mechanics.  Namely, I don't know which function $L(x,f, \nabla f)$ has the above as its Euler-Lagrangien equations.  More precisely, I think I cannot recast the problem as a Lagrangian over several variables but only one field.  Is there a standard way of doing this?  
Perhaps more importantly: Else, is there a standard $L(x,f,\nabla f)$ whose solution is the constant functions?  
 A: In this answer we will rename the scalar field $f\equiv \phi$. 
I) First we investigate if there is an action 
$$\tag{1} S[\phi]~=~\int \! d^dx ~{\cal L}(x, \phi(x), \partial \phi(x), \partial^2 \phi(x), \ldots ) $$ 
such that the functional derivative 
$$ \tag{2} E(x)~\equiv~\frac{\delta S}{\delta \phi(x)} $$
is the gradient of the field
$$ \tag{3} E(x) ~\stackrel{?}{=}~ \frac{\partial \phi(x)}{\partial x^i} ?$$
The first problem with eq. (3) is that the coordinate index $i$ on the rhs of eq. (3) does not match the lhs of eq. (3). It seems that the question is only meaningful in one dimension. So let us assume that $x$ is one dimensional. Then eq. (3) reads
$$ \tag{4} E(x) ~\stackrel{?}{=}~ \frac{\partial \phi(x)}{\partial x} .$$
For consistency, we must demand that functional derivatives commute
$$ \tag{5} \frac{\delta E(x)}{\delta \phi(y)}~\stackrel{?}{=}~ (x \longleftrightarrow y). $$
However eq. (4) satisfies an anticommutative relation (6) instead:
$$ \tag{6} \frac{\delta E(x)}{\delta \phi(y)}~\stackrel{(4)}{=}~\frac{\partial }{\partial x}\delta(x-y)~=~-(x \longleftrightarrow y). $$
So even in one dimension there is no action $S[\phi]$ with Euler-Lagrange operator (4).
II) If we are allowed to rewrite the eqs. of motion $\frac{\partial \phi(x)}{\partial x^i}= 0$ in equivalent forms, we could try to consider e.g.
$$ \tag{7} E(x) ~\stackrel{?}{=}~ (\partial \phi(x))^2 ,$$
which also makes sense for higher dimensional $x$ via a dot product. However, again it is straightforward exercise to check that the ansatz (7) does not meet the consistency condition (5).
