Solve $\operatorname{diag}(x) \nabla f(x)= A x, f(0)=0$ How to solve the following equation:
$$
\operatorname{diag}(x)  \nabla f(x)= A x
$$
where $f: \mathbb{R}^n \to \mathbb{R}$ and $A \in \mathbb{R}^{n \times n}$ with condition $f(0)=0$.  Assume column vectors are used.  Here $\operatorname{diag}(x)$ for a vector $x$ is a squared matrix where $x$ forms a main diagonal.  $\nabla f(x)$ is a gradient of $f$.
Here is my approach.
$$
\nabla f(x) = \operatorname{diag}^{-1}(x)  A x.
$$
Now using FTC and choosing $r(t)=(1-t)0+t*x$
\begin{align}
f(x)=f(r(1))&= \int_0^1  \nabla f(r(t)) \cdot r'(t) \,\mathrm dt\\
&= \int_0^1  x^T \operatorname{diag}^{-1}(tx)  A tx \,\mathrm dt\\
&= x^T \operatorname{diag}^{-1}(x)  A x\\
&= \mathbb{1}^TA x
\end{align}
where $\mathbb{1}$ is a vector of of all ones. 
However, upon checking we have that
$$
\nabla f(x)= \nabla  \mathbb{1}^TA x= A^T  \mathbb{1}
$$
and now checkign the differential equation
$$
\operatorname{diag}(x)  A^T  \mathbb{1}= A x .
$$
However, I don't think the above equality is true.   I am not sure where I am making a mistake. 
Edit 2: From one of the answers, it appears that the solution exists only if,  $A$ is a diagonal matrix. 
 A: It is sometimes useful to look at subcases in order to get an intuition about the problem and its solution.


*

*If $n=1$, then we consider the differential equation $x f'(x) = A x$, $f(0) = 0$. The differential equation is always satisfied at $x=0$, for all $f$, $A$. For $x\neq 0$, we can divide on both sides, and we obtain the solution $f(x) = A x$.

*If $n=2$, then we consider the PDE system
$$
\begin{aligned}
x_1 f_{,1}(x) &= A_{11} x_1 + A_{12} x_2 \\
x_2 f_{,2}(x) &= A_{21} x_1 + A_{22} x_2 \, .
\end{aligned}
$$
With a similar reasoning, the first equation yields $f(x) = A_{11} x_1 + A_{12} x_2\ln x_1 + c_1(x_2)$. Substitution in the second equation gives $c'_1(x_2) = A_{21} x_1/x_2 + A_{22} - A_{12} \ln x_1$, which is supposed to be a function of $x_2$ only. Thus, $A_{21} = A_{12} = 0$ is required, and we have $$f(x) = A_{11} x_1 + A_{22} x_2 \, ,$$ by using the initial condition.
Hope this helps for solving the general case, which partial resolution in OP looks fine.

Hint: The linear system of algebraic equations $\text{diag}(x)A^\top 1 = Ax$ may be rewritten as
$$
\sum_{j\neq i} (A_{ji} x_i - A_{ij} x_j) = 0 \qquad \forall\, i\in \lbrace1\dots n\rbrace ,\; \forall\, x
$$
which is of the form $Bx = 0$. Since this identity must be true for all $x$, the matrix $B$ has to be equal to zero, which is already the case for $n=1$. In the case $n=2$, we end up with the condition $A_{21} = A_{12} = 0$. In the general case, the previous linear system implies that $A$ has to be diagonal.
Following this post, one may alternatively use the fact that $\nabla f(x) = \text{diag}(x)^{-1}\! A x$ leads to the identity $\text{curl} (\text{diag}(x)^{-1}\! A x) = 0$ to be satisfied for all $x$.
A: Making 
$$
x^{\dagger}\text{diag}(x)\nabla f = x^{\dagger}Ax
$$
we have
$$
\sum_{i=1}^n x_i^2 f_{x_i} = x^{\dagger}Ax
$$
This is a linear PDE and the homogeneous have the solution
$$
f_h(x) = \eta\left(\frac{x_2-x_1}{x_1x_2},\cdots,\frac{x_k-x_1}{x_1x_k},\cdots,\frac{x_2-x_1}{x_1x_n} \right)
$$
NOTE
$$
\frac{dx_1}{x_1^2}=\frac{dx_2}{x_1^2}=\cdots=\frac{dx_n}{x_n^2}
$$
for $n = 2$
$$
\frac{1}{x_1}=\frac{1}{x_2}+C\Rightarrow \frac{x_2-x_1}{x_1x_2}=C\Rightarrow f(x_1,x_2) = \eta\left(\frac{x_2-x_1}{x_1x_2}\right)
$$
etc.
Now regarding a non homogeneous case. Considering for $n=3$
$$
\sum_{i=1}^n x_i^2 f_{x_i} = \sum_{i=1}^n\lambda_ix_i^2
$$
and making the variable changes
$$
\cases{
\eta_1 = \frac{x_2-x_1}{x_2x_1}\\
\eta_2 = \frac{x_3-x_1}{x_3x_1}\\
\eta_3 = \frac{x_3+x_1}{x_3x_1}
}
$$
the PDE is reduced to
$$
f_{\eta_3}(\eta_1,\eta_2,\eta_3)= -2\left(\frac{\lambda_1}{(\eta_2-\eta_3)^2}+\frac{\lambda_2}{(\eta_2+\eta_3)^2}+\frac{\lambda_3}{(\eta_3+\eta_2-2\eta_1)^2}\right)
$$
which is directly solvable.  The same procedure can be followed to solve the general case.
For $n = 3$ the complete case is simply 
$$
f_{\eta_3}(\eta_1,\eta_2,\eta_3) = -2\left(\frac{a_{11}}{(\eta_2-\eta_3)^2}+\frac{a_{22}}{(\eta_2+\eta_3)^2}+\frac{a_{33}}{(\eta_3+\eta_2-2\eta_1)^2}-2\left(\frac{a_{23}}{(\eta_2-\eta_3)(\eta_2+\eta_3-2\eta_1)}+\frac{a_{12}}{(\eta_2+\eta_3)(\eta_2+\eta_3-2\eta_1)}-\frac{a_{13}}{\eta_2^2-\eta_3^2}\right)\right)
$$
