Let $f$ be a smooth function on $\mathbb{R}^d$. We write $\nabla^2f$ for the Hessian matrix of $f$.
For $x \in \mathbb{R}^d$, we write $\{a_j(x)\}_{j=1}^d$ for the eigenvalue of $\nabla^2 f(x)$. Then, we have \begin{align*} \Delta f(x)=\text{Trace}[\nabla^2 f(x)]=\sum_{j=1}^d a_j(x). \end{align*}
My question
Let $\{b_j\}_{j=1}^d$ be $\mathbb{R}$-valued functions on $\mathbb{R}^d$.
In general, the following formula does not hold: \begin{align*} \text{Trace}[B(x)\nabla^2 f(x)]=\sum_{j=1}^d b_j(x)a_j(x),\quad x \in \mathbb{R}^d. \end{align*} Here, $B(x)$ denotes the $d$-dimensional diagonal matrix whose $(j,j)$-th element is $b_j(x)$. However, is it possible to describe $\sum_{j=1}^d b_j(x)a_j(x)$ using $\nabla^2 f(x)$ and $B(x)$?