$$\begin{array}{ll} \text{minimize} & \Vert \mathbf{x-Da}\Vert_2^2\\ \text{subject to} & \sum \mathbf{a}_i=1\\ & \mathbf{a}_i \geq 0\end{array}$$
How to convert this problem into an equivalent quadratic program so that I can use Matlab's quadprog function to solve this?
Hint: $||\mathbf{x-Da}\Vert_2^2$ is equivalent to
$(\mathbf{x-Da})^T\cdot (\mathbf{x-Da})=(\mathbf{x^T-a^TD^T})\cdot (\mathbf{x-Da})$
$=\mathbf{x^Tx-x^TDa-D^Ta^Tx+a^TD^TDa}$