Calculates the QR decomposition of a matrix.