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)