00001 #ifndef vnl_qr_h_ 00002 #define vnl_qr_h_ 00003 00004 //: 00005 // \file 00006 // \brief Calculate inverse of a matrix using QR 00007 // \author Andrew W. Fitzgibbon, Oxford RRG, 08 Dec 96 00008 // 00009 // Modifications: 00010 // 081296 AWF Temporarily abandoned as I realized my problem was symmetric... 00011 // 080697 AWF Recovered, implemented solve(). 00012 // 200897 AWF Added determinant(). 00013 // 071097 AWF Added Q(), R(). 00014 // Christian Stoecklin, ETH Zurich, added QtB(v); 00015 // 31-mar-2000 fsm@robots.ox.ac.uk: templated 00016 // dac (Manchester) 28/03/2001: tidied up documentation 00017 00018 #include <vnl/vnl_vector.h> 00019 #include <vnl/vnl_matrix.h> 00020 00021 //: Calculate QR decomposition of a matrix. 00022 // More detailed description not available 00023 00024 export template <class T> 00025 class vnl_qr { 00026 public: 00027 vnl_qr(vnl_matrix<T> const & M); 00028 ~vnl_qr(); 00029 00030 vnl_matrix<T> inverse () const; // inverse 00031 vnl_matrix<T> tinverse () const; // transpose-inverse 00032 vnl_matrix<T> recompose () const; 00033 00034 vnl_matrix<T> solve (const vnl_matrix<T>& rhs) const; 00035 vnl_vector<T> solve (const vnl_vector<T>& rhs) const; 00036 00037 T determinant() const; 00038 vnl_matrix<T>& Q(); 00039 vnl_matrix<T>& R(); 00040 vnl_vector<T> QtB(const vnl_vector<T>& b) const; 00041 00042 void extract_q_and_r(vnl_matrix<T>* Q, vnl_matrix<T>* R); 00043 00044 private: 00045 vnl_matrix<T> qrdc_out_; 00046 vnl_vector<T> qraux_; 00047 vnl_vector<int> jpvt_; 00048 vnl_matrix<T>* Q_; 00049 vnl_matrix<T>* R_; 00050 00051 // Disallow assignment until I decide whether it's a good idea 00052 vnl_qr(const vnl_qr<T> &) { } 00053 void operator=(const vnl_qr<T> &) { } 00054 }; 00055 00056 //: Compute determinant of matrix "M" using QR. 00057 template <class T> 00058 inline T vnl_qr_determinant(vnl_matrix<T> const& m) 00059 { 00060 return vnl_qr<T>(m).determinant(); 00061 } 00062 00063 export template <class T> 00064 vcl_ostream& operator<<(vcl_ostream&, vnl_qr<T> const & qr); 00065 00066 #endif // vnl_qr_h_