我试图获得协方差矩阵的特征值和特征向量的最小值:
Eigen::Matrix3d covariance_matrix; //has to be Matrix3d
double minEigenValue = 0;
int minEigenVectorIndex = 0;
//compute covariance matrix
Eigen::EigenSolver<Eigen::Matrix3d > solver(covariance_matrix);
Eigen::Matrix eigenvalues = solver.eigenvalues();
// Eigen::Matrix3d eigenvalues = solver.eigenvalues(); results in an error
for(int i = 0; i < 3;i++)
{
//How do I access the eigenvalues? This fails. eigenvalues[0][i] also fails
if(eigenvalues(0,i) > minEigenValue)
{
minEigenValue = eigenvalues(0,i);
minEigenVectorIndex = i;
}
}
// somehow get pair of vector[0], vector[1], vector[2]:
//solver.eigenvectors().col(minEigenVectorIndex);
我已经阅读了相当多的文档,但找不到明确的示例/解释 如何访问特征向量和值?
答案 0 :(得分:2)
Eigen::Matrix<std::complex<double>,3,1> eigenvalues = solver.eigenvalues();
Eigen::Matrix<std::complex<double>,3,3> eigenvec = solver.eigenvectors();