i usually come across this equation and I am not able to understand it entirely, here X, W and Y are matrices of size N*D, D*1, and N*1 resp. $(Y-XW)^T(Y-XW)$.
As per me it should be equal to $Y^TY-Y^TXW-W^TX^TY+W^TX^TXW$ but actually it comes out to be $Y^TY-2W^TX^TY+W^TX^TXW$. I simply could not find any explanation for this.