Folks. When I'm trying to calculate determinant, I got a trouble with my matrix sometimes. At this picture you can see the problem with the (2, 2) member. That is so rare case. My function:
double_t Determinant(const ublas::matrix<double_t> & matrix)
{
// boost::numeric::ublas
ublas::matrix<double_t> mLu(matrix);
ublas::permutation_matrix<std::size_t> pivots(matrix.size1());
std::cout << "BEFORE FACTORIZE" << std::endl;
PrintMatrix(mLu); // just printing the matrix
if (ublas::lu_factorize(mLu, pivots)) // there are some problems here
{
return 0.0;
}
std::cout << std::endl << "AFTER FACTORIZE" << std::endl;
PrintMatrix(mLu); // just printing the matrix
double_t det = 1.0;
for (std::size_t i = 0; i < pivots.size(); ++i)
{
det *= (pivots(i) != i ? -1. : 1.) * mLu(i, i);
}
return det;
}
How to fix that? Thanks.