TITLE: Vector derivation of $x^Tx$
QUESTION [15 upvotes]: Let $x \in \mathbb{R}^n$
What is
$$\frac{\partial}{\partial x} [ x^Tx ]$$
My guess is: $\frac{\partial}{\partial x} [ x^Tx ] = 0$, because $[x^Tx] \in \mathbb{R}^1$, hence a real number as is interpreted as scalar in this derivation.

REPLY [15 votes]: Write x as $(x_1, x_2, \cdots, x_n)$.  Then $x^t x = \sum_i x_i^2$.  So, for example,
$$\frac{d}{dx_1} x^t x = \frac{d}{dx_1} \left( \sum x_i^2\right) = \frac{d}{dx_1} x_1^2 = 2x_1$$
and similarly for each of the other components of $x$.  From this it should be clear that
$$\frac{d}{dx} x^t x = 2x^t$$
(The transpose is there because the derivative is a map $\mathbb{R}^n\rightarrow\mathbb{R}$, so expressed as a matrix it must have dimension $1\times n$, or alternatively, as a linear map it must live in the dual space to $\mathbb{R}^n$, i.e. the space of linear maps $\mathbb{R}^n \rightarrow \mathbb{R}$.)
Your question perhaps betrays some confusion as to what the derivative is.  Although for each $x$ the value of $x^t x$ is a single number, i.e. a scalar, the derivative expresses the amount by which $x^t x$ changes as the entries of $x$ change.  This is surely nonzero, since the value of $x^t x$ depends on the entries of $x$.