QR Factorization of a Rectangular Matrix

GEQP3 is a FORTRAN77 library which contains the portion of the LAPACK library that carries out the QR factorization, with column pivoting, of an M by N rectangular matrix, with N <= M.

The factorization can be written as

       A = Q *  R0 * P'

         = Q * (R) * P',

The rank of A can be estimated by the rank of R, which, in turn, can be estimated by taking a tolerance T, and comparing the consecutive diagonal elements of R to T * R(1,1). If K is the last diagonal element which is at least T * R(1,1) in magnitude, we estimate the rank as K.

Thereafter, a least squares soluation of the linear system A*X=B can be determined by:

        X = P * ( inv ( R(1:k,1:k) ) * ( Q' * B )(1:k,1:k) )
                ( 0                                        )   


The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.


GEQP3 is available in a FORTRAN77 version and a FORTRAN90 version.

Related Programs:

BAND_QR, a FORTRAN77 library which computes the QR factorization of a banded matrix, and can solve related linear systems, by Alfredo Remon, Enrique Quintana-Orti, Gregorio Quintana-Orti.

LAPACK_EXAMPLES, a FORTRAN77 program which demonstrates the use of the LAPACK linear algebra library.

LINPACK, a FORTRAN77 library which solves linear systems for a variety of matrix storage schemes, real or complex arithmetic, and single or double precision. It includes a routine for computing the singular value decomposition (SVD) of a rectangular matrix. The original version of this library is by Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart.

QR_SOLVE, a FORTRAN77 library which computes the least squares solution of a linear system A*x=b.


  1. Edward Anderson, Zhaojun Bai, Christian Bischof, Susan Blackford, James Demmel, Jack Dongarra, Jeremy DuCroz, Anne Greenbaum, Sven Hammarling, Alan McKenney, Danny Sorensen,
    LAPACK User's Guide,
    Third Edition,
    SIAM, 1999,
    ISBN: 0898714478,
    LC: QA76.73.F25L36

Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the FORTRAN77 source codes.

Last revised on 19 March 2014.