Any square matrix M can be decomposed as M = QR, where Q is orthogonal and R is upper triangular. If M is invertible, then this decomposition is unique if we require the diagonal entries of R to be positive, and the decomposition can be achieved by applying the Gram-Schmidt method to the columns of M. Compare singular value decomposition.