Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-08-25 17:50:07


Am Freitag, 22. August 2008 23:18 schrieb Иволгин Ардалион:
> Nope. I get a run-time assertion from function lu_factorize. Besides
> that I tried different matrixes.

you have been using "int" as type of the matrix elements. Thus the
divisions of the LU-deco resulted in "0" all the time. And therefore,
the computed factors have been wrong. The below example runs fine.

// switch automatic singular check off
#define BOOST_UBLAS_TYPE_CHECK 0

#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/lu.hpp>

using namespace boost::numeric::ublas;

int main () {
  typedef float TYPE;
  matrix<TYPE> A(3,3), B(identity_matrix<TYPE>(3));
  for (int i=0; i<3; ++i)
    for (int j=0; j<3; ++j)
      A(i,j)=3*(i+4)/(7-i-j);
    
  std::cout << A << std::endl;
  std::cout << B << std::endl;
    
  permutation_matrix<> pm(3);
    
  int result = lu_factorize<matrix<TYPE>, permutation_matrix<> >(A, pm);

  if ( 0 == result ) {
    std::cout << "A =" << A << std::endl;
    std::cout << "pm=" << pm << std::endl;

    lu_substitute(A, pm, B);
    
    std::cout << "LU = " << A << std::endl;
    std::cout << "inv = " << B << std::endl;

  } else {
    std::cout << "LU break down at row " << result << std::endl;
  }

  return EXIT_SUCCESS;
}

output:
[3,3]((1,2,2),(2,3,3),(3,4,6))
[3,3]((1,0,0),(0,1,0),(0,0,1))
A =[3,3]((3,4,6),(0.333333,0.666667,0),(0.666667,0.5,-1))
pm=[3](2,2,2)
LU = [3,3]((3,4,6),(0.333333,0.666667,0),(0.666667,0.5,-1))
inv = [3,3]((-3,2,-7.94729e-08),(1.5,0,-0.5),(0.5,-1,0.5))

mfg
Gunter