How to compute basis of nullspace with Eigen library?

后端 未结 3 1112
孤街浪徒
孤街浪徒 2021-01-22 10:10

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

3条回答
  •  无人及你
    2021-01-22 10:39

    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 mat37(3,7);
    mat37 = MatrixXd::Random(3, 7);
    
    CompleteOrthogonalDecomposition > 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';
    

提交回复
热议问题