代码之家  ›  专栏  ›  技术社区  ›  JaeJun LEE

如何用特征库计算空空间的基?

  •  2
  • JaeJun LEE  · 技术社区  · 9 年前

    如何计算 零空间的基础 矩阵的特征库?

    我试图找到 显式函数名 计算空基,并且作为一种变通方法,找到 矩阵的rref计算 (因为我们能够从rref获得空基)。

    但我找不到任何相关的函数名称。

    我认为这一定有解决方案,但我对Eigen库了解不多,Eigen的代码也很难理解。

    请给我建议这个问题的解决方案。

    3 回复  |  直到 9 年前
        1
  •  13
  •   ggael    9 年前

    您可以使用 Eigen::FullPivLU::kernel() 方法:

    FullPivLU<MatrixXd> lu(A);
    MatrixXd A_null_space = lu.kernel();
    
        2
  •  4
  •   Gokul    6 年前

    FullPivLU在Eigen中计算成本最高, http://eigen.tuxfamily.org/dox/group__DenseDecompositionBenchmark.html .

    更快的替代方法是使用完全正交分解。此代码使用矩阵的四个基本子空间(google四个子空间和URV分解):

    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';
    
        3
  •  1
  •   Alan    7 年前

    备选:使用OpenCV计算空空间:

    `
    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;
    }`