Possible proof for the relation involving matrix trace Suppose a diagonal matrix $D\in\mathbb{R}^{n\times n}$ is given, with all its entries $d_{ii}\geq0$, for all $i$. Is it possible to prove
$\operatorname{tr}(X^TDX)-2\operatorname{tr}(X^TDY)+\operatorname{tr}(Y^TDY)\geq 0$
for some $X, Y\in\mathbb{R}^{n\times 2}$. The above reminds to $a^2+b^2\geq2ab$, but I would need a proof in matrix terms. Also, if the above is true, for which range of $b$ is the following true
$(2-b)\operatorname{tr}(X^TDX)-2(2-b)\operatorname{tr}(X^TDY)+\operatorname{tr}(2-b)(Y^TDY)\geq 0$
 A: Assume $$A=D^{\frac{1}{2}}X $$
$$B=D^{\frac{1}{2}}Y $$
$$tr(A-B)^{T}(A-B)\geq 0$$
The left is obvious
A: We have 
\begin{align*}\operatorname{Tr}(X^TDX)-2\operatorname{Tr}(X^TDY)+\operatorname{Tr}(Y^TDY)&=\operatorname{Tr}(X^TD(X-Y))+\operatorname{Tr}((Y^T-X^T)DY)\\
&=\operatorname{Tr}(X^TD(X-Y))+\operatorname{Tr}(Y^TD(Y-X))\\
&=\operatorname{Tr}((X-Y)^TD(X-Y))\\
&=\operatorname{Tr}(D(X-Y)(X-Y)^T).\\
\end{align*}
Now $(X-Y)(X-Y)^T$ is positive semi-definite so it's diagonal entries are non-negative and since $D_{ii}\geq 0$ for all $i$ the diagonal entries of $D(X-Y)(X-Y)^T$ are non-negative.
For the second question, you can factor $(2-b)$ and you see that it needs to be non-negative.
A: Think of $X$ as $(\vec x_1,\vec x_2)$ and $Y$ accordingly. So you might write it like
$$
\sum_{k=1,2} \langle x_k|Dx_k\rangle -2\langle x_k|Dy_k\rangle +\langle y_k|Dy_k\rangle
=\sum_{k=1,2} \langle x_k-y_k|D(x_k-y_k)\rangle=\sum_{k=1,2} \langle z_k|Dz_k\rangle \geq 0.
$$
Since $D$ is diagonal with entries $\geq 0$, you get 
$$
\langle z_k|Dz_k\rangle = \sum_{i=1}^N d_{i,i} \cdot \left((z_k)_i\right)^2 \geq 0.
$$
