2013-06-21 1 views
4

부스트를 사용하여 간단한 행렬 반전 연산을 수행하려고합니다. 하지만 오류가 발생했습니다. 는 기본적으로 내가 무엇을 찾기 위해 시도하고 inversted_matrix = 역 (트랜스 (매트릭스) * 매트릭스) 이다 그러나 나는 오류부스트에서 행렬 반전

Check failed in file boost_1_53_0/boost/numeric/ublas/lu.hpp at line 299: 
detail::expression_type_check (prod (triangular_adaptor<const_matrix_type, 
upper> (m), e), cm2) 
terminate called after throwing an instance of 
'boost::numeric::ublas::internal_logic' 
    what(): internal logic 
Aborted (core dumped) 
을 얻고있다

내 시도 :

#include <boost/numeric/ublas/matrix.hpp> 
#include <boost/numeric/ublas/vector.hpp> 
#include <boost/numeric/ublas/io.hpp> 
#include <boost/numeric/ublas/vector_proxy.hpp> 
#include <boost/numeric/ublas/matrix.hpp> 
#include <boost/numeric/ublas/triangular.hpp> 
#include <boost/numeric/ublas/lu.hpp> 

namespace ublas = boost::numeric::ublas; 
template<class T> 
bool InvertMatrix (const ublas::matrix<T>& input, ublas::matrix<T>& inverse) { 
    using namespace boost::numeric::ublas; 
    typedef permutation_matrix<std::size_t> pmatrix; 
    // create a working copy of the input 
    matrix<T> A(input); 
    // create a permutation matrix for the LU-factorization 
    pmatrix pm(A.size1()); 
    // perform LU-factorization 
    int res = lu_factorize(A,pm); 
    if(res != 0) 
     return false; 
    // create identity matrix of "inverse" 
    inverse.assign(ublas::identity_matrix<T>(A.size1())); 
    // backsubstitute to get the inverse 
    lu_substitute(A, pm, inverse); 
    return true; 
} 

int main(){ 
    using namespace boost::numeric::ublas; 
    matrix<double> m(4,5); 
    vector<double> v(4); 
    vector<double> thetas; 
    m(0,0) = 1; m(0,1) = 2104; m(0,2) = 5; m(0,3) = 1;m(0,4) = 45; 
    m(1,0) = 1; m(1,1) = 1416; m(1,2) = 3; m(1,3) = 2;m(1,4) = 40; 
    m(2,0) = 1; m(2,1) = 1534; m(2,2) = 3; m(2,3) = 2;m(2,4) = 30; 
    m(3,0) = 1; m(3,1) = 852; m(3,2) = 2; m(3,3) = 1;m(3,4) = 36; 
    std::cout<<m<<std::endl; 
    matrix<double> product = prod(trans(m), m); 
    std::cout<<product<<std::endl; 
    matrix<double> inversion(5,5); 
    bool inverted; 
    inverted = InvertMatrix(product, inversion); 
    std::cout << inversion << std::endl; 
} 
+1

[this] (http://lists.boost.org/MailArchives/ublas/2011/08/5007.php) 도움이 될 수 있습니까? – soon

답변

6

부스트 Ublas 런타임 검사를 가지고 다른 것들 중에서 숫자 안정성을 보장합니다. 오류의 원인을 보면 U*X = B, X = U^-1*B, U*X = B (또는 그와 같은 smth)이 일부 엡실론 안에 연계되어 있는지 확인하려고하는 것을 볼 수 있습니다. 숫자가 너무 많이 벗어난다면 이것은 유지되지 않을 것입니다.

-DBOOST_UBLAS_NDEBUG을 통해 수표를 사용 중지하거나 BOOST_UBLAS_TYPE_CHECK_EPSILON, BOOST_UBLAS_TYPE_CHECK_MIN을 사용하여 수표를 사용 중지 할 수 있습니다. m로서

3

만 4 행 prod(trans(m), m) 4보다 랭크가 없으며, 제품은 5 × 5 행렬이기 때문에, 그것은 단일 여야을 갖는다 (즉, 그 결정 0을 가짐) 및 특이 행렬의 역행렬을 계산하는 단계와 같다 이 특이점 문제를 해결하기 위해 m에 독립 행을 추가하십시오.