functions to compute xtx and xty