Module: Linear Algebra Group: Factorization classes
Does not inherit
#include <rw/math/genmat.h> // RWGenMat<T>, class T general #include <rw/lapack/pdfct.h> #include <rw/lapack/pdbdfct.h> #include <rw/lapack/pdtdfct.h> RWGenFact<double> LU(A); // A is a RWGenMat<double> RWPDFact<double> LU4(D); // D is a RWPDMat<double> RWPDTriDiagFact<double> LU7(G); // G is a
// RWPDTriDiagMat<double>
The classes RWPDFact<T>, RWPDBandFact<T>, and RWPDTriDiagFact<T> encapsulate factorizations of positive definite symmetric matrices, which are Hermitians in the complex case. These classes produce a valid factorization only if the matrix being factored is positive definite. If the matrix is not positive definite, attempting to use the factorization to solve a system of equations results in an exception being thrown. To test if the factorization is valid, use the good or fail member functions.
#include <iostream> #include <rw/dgenfct.h> int main() { // Read in a matrix and a right-hand side and
// print the solution RWGenMat<double> A; RWMathVec<double> b; std::cin >> A >> b; RWGenFact<double> LU(A); if (LU.good()) { std::cout << "solution is " << solve(LU,b) << std::endl; } else { std::cout << "Could not factor A, perhaps it is singular" << std::endl; } return 0; }
RWGenFact<T>(); RWPDFact(); RWPDBandFact(); RWPDTriDiagFact();
Default constructor. Builds a factorization of a 0 x 0 matrix. You use the member function factor to fill in the factorization.
RWGenFact<T>(const RWGenMat<T>& A, bool ec=true); RWPDFact<T>(const RWSymMat<T>& A, bool ec=true); RWPDBandFact<T>(const RWBandMat<T>& A,
bool ec=true); RWPDTriDiagFact<T>(const RWTriDiagMat<T>& A,
bool ec=true);
Constructs a factorization of the matrix A. This factorization can be used to solve systems of equations, and to calculate inverses and determinants. If the parameter ec is true, you can use the function condition to obtain an estimate of the condition number of the matrix. Setting ec to false can save some computation if the condition number is not needed.
unsigned
cols() const;
Returns the number of columns in the matrix represented by this factorization.
void
factor(const RWGenMat<T>& A, bool void ec=true);
Factors a matrix. Calling factor replaces the current factorization with the factorization of the matrix A. This is commonly used to initialize a factorization constructed with the default (no arguments) constructor.
bool
fail() const; bool
good() const;
Checks whether the factorization is successfully constructed. If good returns false or fail returns true, attempting to use the factorization to solve a system of equations results in an exception being thrown.
bool isPD() const;
Tests if the matrix is positive definite. If the matrix is not positive definite, the factorization is not complete and you cannot use the factorization to solve systems of equations.
bool
isSingular() const;
Tests if the matrix is singular to within machine precision. If the factorization is a positive definite type and the matrix that was factored is not actually positive definite, then isSingular may return true regardless of whether or not the matrix is actually singular.
unsigned
rows() const;
Returns the number of rows in the matrix represented by this factorization.
float condition(const RWPDFact<float>& A); double condition(const RWPDFact<double>& A); double condition(const RWPDFact<DComplex>& A); float condition(const RWPDBandFact<float>& A); double condition(const RWPDBandFact<double>& A); double condition(const RWPDBandFact<DComplex>&
A); float condition(const RWPDTriDiagFact<float>&
A); double condition(const RWPDTriDiagFact<double>&
A); double condition(const
RWPDTriDiagFact<DComplex>& A); double condition(const RWGenFact<T>& A);
Calculates the reciprocal condition number of the matrix represented by this factorization. If this number is near 0, the matrix is ill-conditioned and solutions to systems of equations computed using this factorization may not be accurate. If the number is near 1, the matrix is well-conditioned. For the condition number to be computed, the norm of the matrix must be computed at the time the factorization is constructed. If you set the optional boolean parameter in the constructor or the factor member function to false, calling condition generates an exception.
T determinant(const RWGenFact<T>& A); T determinant(const RWPDFact<T>& A); T determinant(const RWPDBandFact<T>& A); T determinant(const RWPDTriDiagFact<T>& A);
Calculates the determinant of the matrix represented by this factorization.
RWGenMat<T> inverse(const
RWGenFact<T>&); RWSymMat<float> inverse(const
RWPDFact<float>&); RWSymMat<double> inverse(const
RWPDFact<double>&); RWHermMat<DComplex> inverse(const
RWPDFact<DComplex>&);
Computes the inverse of the matrix represented by this factorization. Although matrix inverses are very useful in theoretical analysis, they are rarely necessary in implementation. A factorization is nearly always as useful as the actual inverse, and can be constructed at far less cost.
RWMathVec<T> solve(const RWGenFact<T>& A, const RWMathVec<T>& b); RWMathVec<T> solve(const RWPDFact<T>& A, const RWMathVec<T>& b); RWMathVec<T> solve(const RWPDBandFact<T>& A, const RWMathVec<T>& b); RWMathVec<T> solve(const RWPDTriDiagFact<T>&
A, const RWMathVec<T>&);
Solves a system of equations. Returns the vector x, which satisfies Ax=b, where A is the matrix represented by the factorization. It is wise to call one of the member functions good or fail to make sure that the factorization was successfully constructed.
RWGenMat<T> solve(const RWGenFact<T>& A, const RWGenMat<T>& B); RWGenMat<T> solve(const RWPDFact<T>& A, const RWGenMat<T>& B); RWGenMat<T> solve(const RWPDBandFact<T>& A, const RWGenMat<T>&); RWGenMat<T> solve(const RWPDTriDiagFact<T>& A, const RWGenMat<T>& B);
Solves a system of equations. Returns the matrix X, which satisfies AX=B, where A is the matrix represented by the factorization. It is wise to call one of the member functions good or fail to make sure that the factorization was successfully constructed.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.