How to compute basis of nullspace with Eigen library?

元气小坏坏 提交于 2019-12-11 01:13:57

问题


How to compute basis of nullspace of a matrix with Eigen library?

I tried to find explicit function name to compute null basis and also, as a workaround, to find method for computing rref of a matrix(as we're able to get null basis from rref).

But I couldn't find any relevant functions names.

I think there's must be solution for this, but I know not much about Eigen library and Eigen's code also very difficult to me to understand.

Please suggest me the solution for this problem.


回答1:


You can get a basis of the null space using Eigen::FullPivLU::kernel() method:

FullPivLU<MatrixXd> lu(A);
MatrixXd A_null_space = lu.kernel();



回答2:


Alternative: Use OpenCV to calculate null space:

`
cv::Mat EpipolarConstraint::getNullSpace(cv::Mat p)
{
    cv::SVD svd = cv::SVD(p, cv::SVD::FULL_UV);
    cv::Mat vt_ = svd.vt;
    int i;
    for (i = 1; i <= 3; i++)
    {
        if (p.at<double>(i - 1, i - 1) == 0)
        {
            break;
        }
    }
    cv::Mat result = vt_(cv::Rect(0, i-1, p.cols, vt_.rows-i+1));
    cv::Mat result_t;
    cv::transpose(result, result_t);
    return result_t;
}`



回答3:


FullPivLU is most expensive computationally in Eigen, http://eigen.tuxfamily.org/dox/group__DenseDecompositionBenchmark.html.

A quicker alternative is to use CompleteOrthogonalDecomposition. This code uses four fundamental subspaces of a matrix (google four fundamental subspaces and URV decomposition):

Matrix<double, Dynamic, Dynamic> mat37(3,7);
mat37 = MatrixXd::Random(3, 7);

CompleteOrthogonalDecomposition<Matrix<double, Dynamic, Dynamic> > cod;
cod.compute(mat37);
cout << "rank : " << cod.rank() << "\n";
// Find URV^T
MatrixXd V = cod.matrixZ().transpose();
MatrixXd Null_space = V.block(0, cod.rank(),V.rows(), V.cols() - cod.rank());
MatrixXd P = cod.colsPermutation();
Null_space = P * Null_space; // Unpermute the columns
// The Null space:
std::cout << "The null space: \n" << Null_space << "\n" ;
// Check that it is the null-space:
std::cout << "mat37 * Null_space = \n" << mat37 * Null_space  << '\n';


来源:https://stackoverflow.com/questions/34662940/how-to-compute-basis-of-nullspace-with-eigen-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!