[英]c++ eigenvalue and eigenvector corresponding to the smallest eigenvalue
I am trying to find out the eigenvalues and the eigenvector corresponding to the smallest eigenvalue. 我试图找出对应于最小特征值的特征值和特征向量。 I have a matrix A
(nx2) and I have computed B = transpose(A) * a
. 我有一个矩阵A
(nx2),并且我已经计算出B = transpose(A) * a
。 When I am using c++ eigen function compute()
and print the eigenvalues of matrix B
, it shows something like this: 当我使用c ++特征函数compute()
并打印矩阵B
的特征值时,它显示如下内容:
(4.4, 0)
(72.1, 0)
Printing the eigenvectors it gives output: 打印特征向量可得到输出:
(-0.97, 0) (0.209, 0)
(-0.209, 0) (-0.97, 0)
I am confused. 我很困惑。 Eigenvectors can't be zero I guess. 我猜特征向量不能为零。 So, for the smallest eigenvalue 4.4, is the corresponding eigenvector (-0.97, -0.209)
? 因此,对于最小的特征值4.4,对应的特征向量(-0.97, -0.209)
吗?
PS - when I print PS-当我打印时
mysolution.eigenvalues()[0]
it prints (4.4, 0)
. 它打印(4.4, 0)
。 And when I print 当我打印时
mysolution.eigenvectors().col(0)
it prints (-0.97, 0) (0.209, 0)
. 它打印(-0.97, 0) (0.209, 0)
。 That's why I guess I can assume that for eigenvalue 4.4, the corresponding eigenvector is (-0.97, -0.209)
. 这就是为什么我可以假设对于特征值4.4而言,对应的特征向量为(-0.97, -0.209)
。
I guess you are correct. 我想你是对的。
None of your eigenvalues is null, though. 但是,您的特征值都不为空。 It seems that you are working with complex numbers. 看来您正在处理复数。
Could it be that you selected a complex floating point matrix to do your computations? 是不是您选择了一个复杂的浮点矩阵来进行计算? Something along the lines of MatrixX2cf
or MatrixX2cd
. MatrixX2cf
或MatrixX2cd
。
Every square matrix has a set of eigenvalues. 每个方阵都有一组特征值。 But even if the matrix itself only consists of real numbers, the eigenvalues and -vectors might contain complex numbers (take (0 1;-1 0) for example) 但是,即使矩阵本身仅由实数组成,特征值和-vector也可能包含复数(例如,取(0 1; -1 0))
If Eigen knows nothing about your matrix structure (ie is it symmetric/self-adjoint? Is it orthonormal/unitary?) but still wants to provide you with exact eigenvalues, the only general type that can hold all possible eigenvalues is a complex number. 如果特征值对矩阵结构一无所知(例如,它是对称/自伴的吗?是正交/整正的?),但仍想为您提供准确的特征值,那么可以容纳所有可能特征值的唯一通用类型就是复数。
Thus, Eigen always returns complex numbers which are represented as pairs (a, b) for a + bi. 因此,本征总是返回复数,这些复数表示为a + bi的对(a,b)。 Eigen will only return real numbers if the matrix is self-adjoint, ie SelfAdjointView is used to access the matrix. 如果矩阵是自伴的,则本征仅返回实数,即使用SelfAdjointView来访问矩阵。
If you know for a fact that your matrix only has real eigenvalues, you can just extract the real part by eigenvalue.real
since Eigen returns std::complex values. 如果您知道矩阵仅具有真实特征值的事实,则可以通过eigenvalue.real
提取真实部分,因为Eigen返回std :: complex值。
EDIT: I just realized that if your matrix A has no complex entries, B=transposed(A)*A is self-adjoint and thus you could just use a SelfAdjointView of the matrix to compute the real eigenvalues and -vectors. 编辑:我刚刚意识到,如果矩阵A没有复杂的条目,则B = transposed(A)* A是自伴随的,因此您可以仅使用矩阵的SelfAdjointView来计算实际特征值和-vector。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.