How to compute the derivative of a tensor-product formula? Recently, I encountered a optimization problem in a paper, which can be expressed as follows:
$$
\begin{cases}
\min E(\mathbf X)=\mathbf X^{\mathbf T} \mathbf K \mathbf X\\
\text{s.t. } \mathbf A \mathbf X = \mathbf P
\end{cases}
$$
where, 
$$
\begin{cases}
\mathbf X = [x_0,\cdots,x_{\hat{m}}]^{\mathbf T}\\
\mathbf P = [p_0,\cdots,p_m]^{\mathbf T}\\
\mathbf K=\left(k_{i,j}\right)_{(\hat{m}+1) \times (\hat{m}+1)}\\
\mathbf A=\left(a_{i,j}\right)_{(m+1) \times (\hat{m}+1)}\\
\hat m > m
\end{cases}
$$
That paper applied the Largrange multipler to solve $\mathbf X$ when $E(\mathbf X)$ obtains the minimum value. Namely,

However, I cannot deduce the first row of that formula by myself.
My trial
Firstly, let $\mathbf A =[\mathbf a_0,\mathbf a_1,\cdots,\mathbf a_m]^{\mathbf T}$, then 
$$\mathbf A \mathbf X = \mathbf P \rightarrow e_i=\mathbf a_i \mathbf X - p_i$$
then the Largrange objective function $F(\mathbf X)$ can be denoted as:
$$
F(\mathbf X) = E(\mathbf X) +v_0e_0+\cdots+v_me_m\\
=E(\mathbf X) +\sum_{i=0}^{m}v_i(\mathbf a_i \mathbf X - p_i)\\
=\mathbf X^{\mathbf T} \mathbf K \mathbf X+\sum_{i=0}^{m}v_i(\mathbf a_i \mathbf X - p_i)
$$
(1)Compute the derivative with respect to the Largrange multiplier $v_i$
$$
\frac {\partial F}{\partial v_i}=\mathbf a_i \mathbf X - p_i = 0\\
\Rightarrow \mathbf A \mathbf X = \mathbf P
$$
(2)But I have no idea about computing the derivative with respect to variable $x_i$
$$
\frac {\partial F}{\partial x_i}=\frac {\partial}{\partial x_i}\left[\mathbf X^{\mathbf T} \mathbf K \mathbf X+\sum_{i=0}^{m}v_i(\mathbf a_i \mathbf X - p_i)\right]\\
=\frac {\partial}{\partial x_i}\left[\mathbf X^{\mathbf T} \mathbf K \mathbf X+\sum_{i=0}^{m}v_i\mathbf a_i \mathbf X\right]\\
=\frac {\partial}{\partial x_i}\left[\mathbf X^{\mathbf T} \mathbf K \mathbf X+\mathbf v^{\mathbf T} \mathbf A \mathbf X\right]\\
$$
Here, $\mathbf v=[v_0,\cdots,v_m]^{\mathbf T}$
 A: When computing such derivatives it's useful to do it in index notation (with Einstein summation convention).
We have
$$\frac{\partial}{\partial x_i}[X^TKX] = K_{ab}\frac{\partial x_a}{\partial x_i}x_b + K_{ab}x_a\frac{\partial x_b}{\partial x_i} =  K_{ab}\delta_{ai}x_b + K_{ab}x_a\delta_{bi} = K_{ib} x_b + K_{ai}x_a = [KX + K^TX]_i$$
where $\delta$ is the Kronecker delta. For the second term we have
$$\frac{\partial}{\partial x_i}[v^TAX] = v_a A_{ab}\frac{\partial x_b}{\partial x_i} = v_a A_{ab}\delta_{bi} = v_a A_{ai} = [A^Tv]_i$$
This gives us
$$\frac{\partial}{\partial x_i}[X^TKX + v^TAX]  = KX + K^TX + A^Tv = 0$$
From the definition of $K$ in the paper your reference (Eq. 6 here) we have that $K$ is symmetric so $K = K^T$ and it reduces to
$$\frac{\partial}{\partial x_i}[X^TKX + v^TAX]  = 2KX + A^Tv = 0$$
This is the same formula as you have in the question as the Lagrange multiplier can be redefined $v \to 2v$ without changing the problem (define the Lagrangian as $L = X^TKX + 2v(AX-P)$).
