Gradient of $F(\mathbf{x}) = \|\mathbf{Ax}-\mathbf{b}\|_{2}^2$ So, I have a matrix $A\in\mathbb{R}^{M\times N}$, $M\geq N$ with rank  $N$ and $\mathbf{b}\in\mathbb{R}^M$. Unfortunately I'm a bit rusty on how to do multivariable calculus, so I would like to know how to calculate $\nabla F$ of
$$F(\mathbf{x})=\|\mathbf{Ax}-\mathbf{b}\|_{2}^2$$
I would furthermore also appreciate literature suggestions regarding sources where multivariable calculus is well explained, especially differentiation.
 A: Just apply product- and chain-rule:
$$\begin{align}D_x(\langle F(x),F(x)\rangle)(v)&=
2\langle D_x F(v),F(x)\rangle\\
&=2\langle Av,Ax-b\rangle\\
&=2\langle v,A^t(Ax-b)\rangle,
\end{align}$$
hence
$$\nabla F(x)=2A^t(Ax-b).$$
A: We can always expand $F$. So, we have $F(\mathbf{x})=\|\mathbf{Ax}-\mathbf{b}\|_{2}^2 = \sum_{i=1}^N\left(\sum_{j=1}^M (A_{i,j}x_j - b_j)\right)^2$. Now $\nabla F(x)_k = \sum_{i=1}^N 2A_{i,k}\sum_{j=1}^M(A_{i,j}x_j - b_j)$.
A: Let $$F(x) = \Vert f(x) \Vert_2^2$$
where $f(x) = Ax - b$. Using the fact that $$\frac{d \Vert f(x) \Vert^2}{dx}  = 2\frac{df(x)}{dx}f(x)$$
and that 
$$\frac{df(x)}{dx} = A^T$$
we get
$$\frac{d \Vert f(x) \Vert^2}{dx}  = 2A^T(Ax-b)$$
Why is $\frac{df(x)}{dx} = A^T$ ?
Since $f(x) = Ax - b$ is a vector then a derivative of a vector wrt a vector is defined as 
$$\frac{df(x)}{dx} = \begin{bmatrix} \frac{df_1(x)}{dx_1} &  \frac{df_1(x)}{dx_2} & \ldots &  \frac{df_1(x)}{dx_n} \\ 
\vdots &  \vdots  & \ldots &  \vdots  \\ \frac{df_m(x)}{dx_1} &  \frac{df_m(x)}{dx_2} & \ldots &  \frac{df_m(x)}{dx_n} \end{bmatrix}^T$$
Since the derivative of $Ax-b$ is the same as that of $Ax$, let's consider $f(x) = Ax$, which looks like this 
$$f(x) = Ax = \begin{bmatrix} \sum_{j=1}^n A_{1j}x_j \\ \sum_{j=1}^n A_{2j}x_j \\ \vdots \\ \sum_{j=1}^n A_{mj}x_j \end{bmatrix}$$
Note that it is easy to see that 
$$\frac{df_i(x)}{dx_j} = A_{ij}$$
So we get $\frac{df(x)}{dx} = A^T$. 
Note that some references define $$\frac{df(x)}{dx} = \begin{bmatrix} \frac{df_1(x)}{dx_1} &  \frac{df_1(x)}{dx_2} & \ldots &  \frac{df_1(x)}{dx_n} \\ 
\vdots &  \vdots  & \ldots &  \vdots  \\ \frac{df_m(x)}{dx_1} &  \frac{df_m(x)}{dx_2} & \ldots &  \frac{df_m(x)}{dx_n} \end{bmatrix}$$
which is laying the denominator vector as $x^T$, in that case you'll get that the derivative is $A$ and not its transpose.
