I have already asked this question on math.stackexchange.com
<https://math.stackexchange.com/questions/1789476/is-there-a-matrix-that-converts-the-gradient-of-any-function-to-gradient-of-othe>
Now I realize that Mathoverflow is probably better suited for this question.


The study of hamiltonian mechanics brought me to the following question.


Let $n$ be a natural number ($n>1$).


Let $A(\mathbf{x})$ be a $n\times n$ matrix consisting of functions $a\_{ij}(\mathbf{x})$ ($a\_{ij}:\mathbb{R}^n\to\mathbb{R}$):
$$
A(\mathbf{x})=
\begin{pmatrix}
a\_{11}(\mathbf{x})& \cdots& a\_{1n}(\mathbf{x})\\
\vdots&\ddots&\vdots\\
a\_{n1}(\mathbf{x})&\cdots& a\_{nn}(\mathbf{x})
\end{pmatrix}.
$$
Let $A(\mathbf{x})$ be so, that for *every possible* $F(\mathbf{x})$ ($F:\mathbb{R}^n\to\mathbb{R}$):
$$
\begin{pmatrix}
a\_{11}(\mathbf{x})& \cdots& a\_{1n}(\mathbf{x})\\
\vdots&\ddots&\vdots\\
a\_{n1}(\mathbf{x})&\cdots& a\_{nn}(\mathbf{x})
\end{pmatrix}
\begin{pmatrix}
\frac{\partial F}{\partial x\_1}\\
\vdots\\
\frac{\partial F}{\partial x\_n}
\end{pmatrix}
=
\begin{pmatrix}
g\_1(\mathbf{x})\\
\vdots\\
g\_n(\mathbf{x})
\end{pmatrix}
=
\begin{pmatrix}
\frac{\partial G}{\partial x\_1}\\
\vdots\\
\frac{\partial G}{\partial x\_n}
\end{pmatrix}
$$
for some $G(\mathbf{x})$ ($G:\mathbb{R}^n\to\mathbb{R})$.


In other words, if we multiply *fixed* $A(\mathbf{x})$ by the gradient of *every possible* $F(\mathbf{x})$ we necessarily get the gradient of some $G(\mathbf{x})$.


Can we say anything about such $A(\mathbf{x})$? I would be glad if the only opportunity is that $A(\mathbf{x})=cE$, where $E$ is the identity matrix and $c$ is some real number. Is it correct? Is it possible to prove it?


All the functions are considered to be "good enough" ("smooth enough").


  



**IDEA 1.** $A(\mathbf{x})$ is an arbitrary constant matrix (?).


Counterexample.
$$
F(\mathbf{x})=x\_1x\_2;~A=
\begin{pmatrix}
1&0\\
0&2
\end{pmatrix}
$$
$$
\frac{\partial F}{\partial x\_1}=x\_2;~\frac{\partial F}{\partial x\_2}=x\_1
$$
$$
A
\begin{pmatrix}
\frac{\partial F}{\partial x\_1}\\
\frac{\partial F}{\partial x\_2}
\end{pmatrix}
=
\begin{pmatrix}
1&0\\
0&2\\
\end{pmatrix}
\begin{pmatrix}
x\_2\\
x\_1
\end{pmatrix}
=
\begin{pmatrix}
x\_2\\
2x\_1
\end{pmatrix}
=
\begin{pmatrix}
g\_1(\mathbf{x})\\
g\_2(\mathbf{x})
\end{pmatrix};
$$
$$
\frac{\partial g\_1}{\partial x\_2}=1\neq2=\frac{\partial g\_2}{\partial x\_1}.
$$


  

**IDEA 2.** Chain rule (?)


Counterexample.
$$
F(\mathbf{x})=x\_1x\_2;\\
\mathbf{y}(\mathbf{x}): x\_1=y\_1;~x\_2=2y\_2.\\
\begin{pmatrix}
\frac{\partial x\_1}{\partial y\_1}&\frac{\partial x\_2}{\partial y\_1}\\
\frac{\partial x\_1}{\partial y\_2}&\frac{\partial x\_2}{\partial y\_2}
\end{pmatrix}
\begin{pmatrix}
\frac{\partial F}{\partial x\_1}\\
\frac{\partial F}{\partial x\_2}
\end{pmatrix}
=
\begin{pmatrix}
1&0\\
0&2
\end{pmatrix}
\begin{pmatrix}
x\_2\\
x\_1
\end{pmatrix}
=
\begin{pmatrix}
x\_2\\
2x\_1
\end{pmatrix}
=
\begin{pmatrix}
g\_1(\mathbf{x})\\
g\_2(\mathbf{x})
\end{pmatrix}
=
\begin{pmatrix}
\frac{\partial F}{\partial y\_1}\\
\frac{\partial F}{\partial y\_2}
\end{pmatrix};
$$
$$
\frac{\partial g\_1}{\partial x\_2}=1\neq2=\frac{\partial g\_2}{\partial x\_1}.
$$
Of course,
$$
\frac{\partial^2F}{\partial y\_1\partial y\_2}=\frac{\partial^2F}{\partial y\_2\partial y\_1}
$$
should be valid, but not
$$
\frac{\partial^2F}{\partial y\_1\partial x\_2}\neq\frac{\partial^2F}{\partial y\_2\partial x\_1}.
$$
And, in fact, the latter one is required in the original post.


  



**SOLUTION FOR n=2** @IgorKhavkine helped me a lot.


Proof for $n=2$. All functions below a considered to depend on $\mathbf{x}$.


$$
\begin{pmatrix}
a\_{11}&a\_{12}\\
a\_{21}&a\_{22}
\end{pmatrix}
\begin{pmatrix}
\frac{\partial F}{\partial x\_1}\\
\frac{\partial F}{\partial x\_2}
\end{pmatrix}
=
\begin{pmatrix}
a\_{11}\frac{\partial F}{\partial x\_1}+a\_{12}\frac{\partial F}{\partial x\_2}\\
a\_{21}\frac{\partial F}{\partial x\_1}+a\_{22}\frac{\partial F}{\partial x\_2}
\end{pmatrix}
=
\begin{pmatrix}
g\_1\\
g\_2
\end{pmatrix}.
$$
The condition $\frac{\partial g\_1}{\partial x\_2}=\frac{\partial g\_2}{\partial x\_1}$ may be written as:
$$
\frac{\partial}{\partial x\_2}\left(a\_{11}\frac{\partial F}{\partial x\_1}+a\_{12}\frac{\partial F}{\partial x\_2}\right)=\frac{\partial}{\partial x\_1}\left(a\_{21}\frac{\partial F}{\partial x\_1}+a\_{22}\frac{\partial F}{\partial x\_2}\right).
$$
If we expand it, we get:
$$
\frac{\partial a\_{11}}{\partial x\_2}\frac{\partial F}{\partial x\_1}+a\_{11}\frac{\partial^2F}{\partial x\_2\partial x\_1}+\frac{\partial a\_{12}}{\partial x\_2}\frac{\partial F}{\partial x\_2}+a\_{12}\frac{\partial^2F}{\partial x\_2^2}=\\
=\frac{\partial a\_{21}}{\partial x\_1}\frac{\partial F}{\partial x\_1}+a\_{21}\frac{\partial^2F}{\partial x\_1^2}+\frac{\partial a\_{22}}{\partial x\_1}\frac{\partial F}{\partial x\_2}+a\_{22}\frac{\partial^2F}{\partial x\_1\partial x\_2}\tag 1
$$
We may find $F(\mathbf{x}) $ with arbitrary $\frac{\partial F}{\partial x\_1}=\beta\_1$, $\frac{\partial F}{\partial x\_2}=\beta\_2$, $\frac{\partial^2F}{\partial x\_1^2}=\gamma\_{11}$, $\frac{\partial^2F}{\partial x\_2^2}=\gamma\_{22}$ and $\frac{\partial^2 F}{\partial x\_1 \partial x\_2}=\frac{\partial^2 F}{\partial x\_2 \partial x\_1}=\gamma\_{12}=\gamma\_{21}$ at arbitrary $\mathbf{x}=\mathbf{X}$.
$$
F(\mathbf{x})=\beta\_1(x\_1-X\_1)+\beta\_2(x\_2-X\_2)+\\
+\frac{\gamma\_{11}}{2}(x\_1-X\_1)^2+\gamma\_{21}(x\_1-X\_1)(x\_2-X\_2)+\frac{\gamma\_{22}}{2}(x\_2-X\_2)^2
$$
is an example of such $F(\mathbf{x}$).


Since that we may independently equal the coefficients at each derivative of $F$ in $(1)$. Now we equal coefficients at second derivatives in $(1)$:
$$
\frac{\partial^2 F}{\partial x\_1^2}: a\_{21}=0;\\
\frac{\partial^2 F}{\partial x\_2^2}: a\_{12}=0;\\
\frac{\partial^2 F}{\partial x\_1\partial x\_2}: a\_{11}=a\_{22}.
$$
So $A(\mathbf{x})=a(\mathbf{x})E$ (here $a:\mathbb{R}^n\to\mathbb{R}$).


$a\_{22}(\mathbf{x})=a\_{11}(\mathbf{x})=a(\mathbf{x})$; $a\_{12}(\mathbf{x})=a\_{21}(\mathbf{x})=0$.


If we equal coefficients at first derivatives in $(1)$:
$$
\frac{\partial F}{\partial x\_1}: \frac{\partial a\_{11}}{\partial x\_2}=\frac{\partial a\_{21}}{\partial x\_1}\Rightarrow \frac{\partial a}{\partial x\_2}=0\\
\frac{\partial F}{\partial x\_2}: \frac{\partial a\_{12}}{\partial x\_2}=\frac{\partial a\_{22}}{\partial x\_1}\Rightarrow \frac{\partial a}{\partial x\_1}=0
$$
Thus $a(\mathbf{x})=\mathrm{const}=c$.


So we obtain $A(\mathbf{x})=cE$ and this is what I wanted to prove from the very beginning.


  



**SHORT FINAL SOLUTION FOR ARBITRARY n>1**


See below (courtesy of @IgorKhavkine and @RobertBryant)



Is there a matrix that converts the gradient of every possible function to gradient of other function?
The following considerations hold at least locally (in any sufficiently small open coordinate chart). A vector of functions $g\_i$ is of the form $g\_i = \partial\_i G$ for some function $G$ iff $\partial\_{[j} g\_{i]} = 0$ (Poincaré lemma). A direct calculation gives
$$
 \partial\_{[k} g\_{j]}
 = \partial\_{[k} (a\_{j]}^i \partial\_i F)
 = (\partial\_{[k} a\_{j]}^i) \partial\_i F
 + (a\_{[j}^{(i} \delta\_{k]}^{l)}) \partial\_l \partial\_i F .
$$
Of course, I'm using the notation $A\_{[ij]} = \frac{1}{2}(A\_{ij} - A\_{ji})$ and $A\_{(ij)} = \frac{1}{2}(A\_{ij} + A\_{ji})$. At any point, we could always choose a function $F$ such that $\partial\_i F$ and $\partial\_l \partial\_i F$ are independent and arbitrary. Hence, for your desired condition $\partial\_{[k} g\_{j]} = 0$ to hold at every point, the two coefficients $(\partial\_{[k} a\_{j]}^i)$ and $(a\_{[j}^{(i} \delta\_{k]}^{l)})$ must vanish everywhere. In fact, this is both a necessary and sufficient condition on the coefficient matrix $a^i\_j$.


