Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Math/LA_Qr_decomp.h

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 /**
    00003  * @file LA_Qr_decomp.h
    00004  * Contains class LinAlg::QR
    00005  *
    00006  * @author <a href="mailto:stefanuhrig@gmx.net">Stefan Uhrig</a>
    00007  */
    00008 //------------------------------------------------------------------------------
    00009 #ifndef LINALG_QR_H_INCLUDED
    00010 #define LINALG_QR_H_INCLUDED
    00011 //------------------------------------------------------------------------------
    00012 #include "LA_Vector.h"
    00013 #include "LA_Matrix.h"
    00014 //------------------------------------------------------------------------------
    00015 namespace LA
    00016 {
    00017 //------------------------------------------------------------------------------
    00018 /**
    00019   <p>
    00020   Classical QR Decompisition:
    00021   for an m-by-n matrix A with m >= n, the QR decomposition is an m-by-n
    00022   orthogonal matrix Q and an n-by-n upper triangular matrix R so that
    00023   A = Q*R.
    00024
    00025   <p>
    00026   The QR decompostion always exists, even if the matrix does not have
    00027   full rank, so the constructor will never fail.  The primary use of the
    00028   QR decomposition is in the least squares solution of nonsquare systems
    00029   of simultaneous linear equations.  This will fail if isFullRank()
    00030   returns 0 (false).
    00031
    00032   <p>
    00033   The Q and R factors can be retrived via the getQ() and getR()
    00034   methods. Furthermore, a solve() method is provided to find the
    00035   least squares solution of Ax=b using the QR factors.
    00036
    00037   <p>
    00038   (Adapted from JAMA, a Java Matrix Library, developed by jointly
    00039   by the Mathworks and NIST; see  http://math.nist.gov/javanumerics/jama).
    00040  */
    00041 class QR
    00042 {
    00043 public:
    00044   /**
    00045    * Create a QR factorization object for A.
    00046    * @param A rectangular (rows>=columns) matrix.
    00047    */
    00048   QR(const Matrix& A);
    00049
    00050 public:
    00051   /**
    00052    * Flag to denote the matrix is of full rank.
    00053    * @return true if matrix is full rank, false otherwise.
    00054    */
    00055   bool isFullRank() const;
    00056
    00057   /**
    00058    * Retreive the Householder vectors from QR factorization
    00059    * @returns lower trapezoidal matrix whose columns define the reflections
    00060    */
    00061   Matrix getHouseholder() const;
    00062
    00063   /**
    00064    * Return the upper triangular factor, R, of the QR factorization
    00065    * @return R
    00066    */
    00067   Matrix getR() const;
    00068
    00069   /**
    00070    * Generate and return the (economy-sized) orthogonal factor
    00071    * @return Q the (ecnomy-sized) orthogonal factor (Q*R=A).
    00072    */
    00073   Matrix getQ() const;
    00074
    00075   /**
    00076    * Least squares solution of A*x = b
    00077    * @param b m-length array (vector).
    00078    * @return x n-length array (vector) that minimizes the two norm of Q*R*X-B.
    00079    */
    00080   Vector solve(const Vector& b) const;
    00081
    00082
    00083 private:
    00084   Matrix QR_;
    00085   int m;
    00086   int n;
    00087   Vector Rdiag;
    00088 };
    00089 //------------------------------------------------------------------------------
    00090 }
    00091 //------------------------------------------------------------------------------
    00092 #endif
    00093 //------------------------------------------------------------------------------