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

# Tools/Math/LA_Lu_decomp.h

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 /**
    00003  * @file LA_Lu_decomp.h
    00004  * Contains class LinAlg::LU
    00005  *
    00006  * @author <a href="mailto:stefanuhrig@gmx.net">Stefan Uhrig</a>
    00007  */
    00008 //------------------------------------------------------------------------------
    00009 #ifndef LINALG_LU_H_INCLUDED
    00010 #define LINALG_LU_H_INCLUDED
    00011 //------------------------------------------------------------------------------
    00012 #include <vector>
    00013 #include "LA_Matrix.h"
    00014 //------------------------------------------------------------------------------
    00015 namespace LA
    00016 {
    00017 //------------------------------------------------------------------------------
    00018 /**
    00019  * Performs a LU-decomposition of a matrix.
    00020  * Adapted from Template Numerical Toolkit (TNT) (http://math.nist.gov/tnt/)
    00021  *
    00022  * <P>
    00023  * For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
    00024  * unit lower triangular matrix L, an n-by-n upper triangular matrix U,
    00025  * and a permutation vector piv of length m so that A(piv,:) = L*U.
    00026  * If m < n, then L is m-by-m and U is m-by-n.
    00027  * <P>
    00028  * The LU decompostion with pivoting always exists, even if the matrix is
    00029  * singular, so the constructor will never fail.  The primary use of the
    00030  * LU decomposition is in the solution of square systems of simultaneous
    00031  * linear equations.
    00032  *
    00033  * @author <a href="mailto:stefanuhrig@gmx.net">Stefan Uhrig</a>
    00034  */
    00035 class LU
    00036 {
    00037 public:
    00038   /**
    00039    * Constructs the LU-decomposition of a the passed matrix.
    00040    * @param M Matrix to decompose.
    00041    */
    00042   LU(const Matrix& M);
    00043
    00044 private:
    00045   LU(const LU& lu) {}
    00046   LU& operator=(const LU& lu) { return *this; }
    00047
    00048 public:
    00049   /**
    00050    * True if the matrix is singular.
    00051    * @return True if the matrix is singular.
    00052    */
    00053   bool singular() const;
    00054
    00055   /**
    00056    * Returns the determinant of the matrix.
    00057    * @return The determinant of the matrix.
    00058    */
    00059   double det() const;
    00060
    00061   /**
    00062    * Solves the equation Ax=b.
    00063    * @param b A vector.
    00064    * @return The solution vector x.
    00065    */
    00066   Vector solve(const Vector& b) const;
    00067
    00068   /**
    00069    * Calculates the inverse of the matrix.
    00070    * @return The inverse of the matrix.
    00071    */
    00072   Matrix inverse() const;
    00073
    00074 private:
    00075   Vector permute_copy(const Vector& A, const std::vector<int>& piv) const;
    00076
    00077 private:
    00078   Matrix LU_;
    00079   int m, n;
    00080   int pivsign;
    00081   std::vector<int> piv;
    00082 };
    00083 //------------------------------------------------------------------------------
    00084 }
    00085 //------------------------------------------------------------------------------
    00086 #endif
    00087 //------------------------------------------------------------------------------