and calculate the residual matrix: