How to compute the gradient of
$$\eqalign{
f(x) &= 1^T \left[ \left( x - 1 \left[1^T x\right] \right) \odot \left(x - 1 \left[1^T x\right] \right) \right]\cr
}$$ where $x \in M_{n,1}(\mathbb{R})$, $1 \in M_{n,1}$ is a column vector with all ones, $\odot$ is an element-wise multiplication.
2026-03-28 02:06:37.1774663597
Gradient of $f(x) = 1^T \left[ \left( x - 1 \left[1^T x\right] \right) \odot \left(x - 1 \left[1^T x\right] \right) \right]$ w.r.t. $x$
91 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
Setting the matrix of ones $11^T = J$, we can write $f$ in terms of a variable $a$ with differential:
\begin{align} a&= (I-J)x \\ da &= (I - J)dx \end{align}
where $I$ is the identity matrix.
Replacing $a$ and writing the expression in terms of the Frobenius product we can calculate the differential of $f$:
\begin{align} f &= 1 : a \odot a\\ df &= 1: 2a \odot da\\ &= 1 \odot 2a : da\\ &= 2a : da \\ &= 2(I-J)x : (I - J)dx\\ &= 2(I-J)^2x : dx \end{align}
Thus:
\begin{equation} \frac{\partial f}{\partial x} = 2(I-J)^2x = 2x +2(n-2)Jx \end{equation}
edit: thanks @greg