00001
00002
00003
00004
00005
00006
00007
00008 #ifndef INVERTMATRIX_H_
00009
00010
00011 #include <boost/numeric/ublas/vector.hpp>
00012 #include <boost/numeric/ublas/vector_proxy.hpp>
00013 #include <boost/numeric/ublas/matrix.hpp>
00014 #include <boost/numeric/ublas/triangular.hpp>
00015 #include <boost/numeric/ublas/lu.hpp>
00016 #include <boost/numeric/ublas/io.hpp>
00017
00018 using namespace boost::numeric::ublas;
00019
00020 namespace uvsim
00021 {
00022
00023
00024
00025 template<class T>
00026 bool InvertMatrix (const matrix<T>& input, matrix<T>& inverse)
00027 {
00028 typedef permutation_matrix<std::size_t> pmatrix;
00029
00030 matrix<T> A(input);
00031
00032 pmatrix pm(A.size1());
00033
00034
00035 int res = lu_factorize(A,pm);
00036 if ( res != 0 ) return false;
00037
00038
00039 inverse.assign(identity_matrix<T>(A.size1()));
00040
00041
00042 lu_substitute(A, pm, inverse);
00043
00044 return true;
00045 }
00046
00047 }
00048
00049 #endif