如何在 Eigen 库中获取矩阵的秩?

How to get rank of a matrix in Eigen library?

如何获得rank of a matrix in eigen

您需要将矩阵转换为显示秩的分解。例如FullPivLU。如果你有 matrix3f 它看起来像这样:

FullPivLU<Matrix3f> lu_decomp(your_matrix);
auto rank = lu_decomp.rank();

编辑

分解矩阵是最常用的求秩方式。虽然,如 rank article on wikipedia

中所述,LU 并不是实现浮动值的最可靠方法

When applied to floating point computations on computers, basic Gaussian elimination (LU decomposition) can be unreliable, and a rank-revealing decomposition should be used instead. An effective alternative is the singular value decomposition (SVD), but there are other less expensive choices, such as QR decomposition with pivoting (so-called rank-revealing QR factorization), which are still more numerically robust than Gaussian elimination. Numerical determination of rank requires a criterion for deciding when a value, such as a singular value from the SVD, should be treated as zero, a practical choice which depends on both the matrix and the application.

因此您可能会通过 Eigen::ColPivHouseholderQR< MatrixType >

获得更准确的结果

使用 QR 或 SVD 分解并检查结果矩阵是否也有效。 SVD 可能更可靠。