How to calculate $\nabla_{\mathbf{x}}(\mathbf{c}\mathbf{x}-A)\mathbf{x}^t$ directly?
$\mathbf{x}\in\mathbb{R}^{1\times n}$ , $\mathbf{c}\in\mathbb{R}^{m\times 1}$, $A\in\mathbb{R}^{m\times n}$.
My attempt:
Denote the expression $(\mathbb{c}\mathbf{x}-A)\mathbf{x}^t$ by $f$. Then, find $\frac{\partial f_i}{\partial x_j}$
$f_i = ((\mathbf{c}\mathbf{x}-A)\mathbf{x}^t)_i = \sum_j c_ix_j^2-\sum_jA_{ij}x_j$
$\frac{\partial f_i}{\partial x_j} = 2c_ix_j - A_{ij}$
So, $\nabla_\mathbf{x}(\mathbb{c}\mathbf{x}-A)\mathbf{x}^t = 2\mathbf{c}\mathbf{x}-A.$
Instead of calculating the $ij$-th component, how to compute the gradient directly?
The map $h : x \mapsto (cx-A)x^T$ is defined on $\mathbb R^n$ and takes its values in $\mathbb R^m$. Hence you can't really speak of the gradient as $h$ is not a scalar-valued function.
However, you can speak of the Fréchet (or total) derivative of $h$ at a point $x$.
$f : x \mapsto cx-A$ is an affine map, therefore its Fréchet derivative is constant and equal at each $x \in \mathbb R^n$ to the linear map $u \mapsto cu$. $B : (C,x) \mapsto Cx^T$ is a bilinear map, whose Fréchet derivative at $(C,x)$ is the map $(U,v) \mapsto Ux^T +Cv^T$.
Based on the chain rule, you get
$$h^\prime(x)(u) = (cu)x^T + (cx-A)u^T$$ where $h^\prime(x)$ is the Fréchet derivative of $h$ at $x$.
Moreover because matrix product is associative and inner product commutative, you have $$(cu)x^T= c(u x^T) = c(xu^T) = (cx)u^T$$ which allows to conclude to
$$h^\prime(x)(u) = (2cx-A)u^T.$$
In terms of Matrix calculus, it means that $$\frac{\partial h}{\partial x} = 2cx - A.$$