Matlab VS Python - eig(A,B) VS sc.linalg.eig(A,B) [英] Matlab VS Python - eig(A,B) VS sc.linalg.eig(A,B)
问题描述
我有以下矩阵 sigma 和 sigmad:
I have the following matrices sigma and sigmad:
西格玛:
1.9958 0.7250
0.7250 1.3167
西格玛:
4.8889 1.1944
1.1944 4.2361
如果我尝试在 python 中解决广义特征值问题,我会得到:
If I try to solve the generalized eigenvalue problem in python I obtain:
d,V = sc.linalg.eig(matrix(sigmad),matrix(sigma))
V:
-1 -0.5614
-0.4352 1
如果我尝试解决 g.e.我在 matlab 中遇到的问题:
If I try to solve the g. e. problem in matlab I obtain:
[V,d]=eig(sigmad,sigma)
V:
-0.5897 -0.5278
-0.2564 0.9400
但 d 确实重合.
推荐答案
特征向量的任何(非零)标量倍数也将是特征向量;只有方向有意义,没有整体归一化.不同的例程使用不同的约定——通常你会看到幅度设置为 1,或者最大值设置为 1 或 -1——并且出于性能原因,某些例程甚至不打扰内部一致.您的两个不同结果是彼此的倍数:
Any (nonzero) scalar multiple of an eigenvector will also be an eigenvector; only the direction is meaningful, not the overall normalization. Different routines use different conventions -- often you'll see the magnitude set to 1, or the maximum value set to 1 or -1 -- and some routines don't even bother being internally consistent for performance reasons. Your two different results are multiples of each other:
In [227]: sc = array([[-1., -0.5614], [-0.4352, 1. ]])
In [228]: ml = array([[-.5897, -0.5278], [-0.2564, 0.94]])
In [229]: sc/ml
Out[229]:
array([[ 1.69577751, 1.06366048],
[ 1.69734789, 1.06382979]])
所以它们实际上是相同的特征向量.将矩阵视为改变向量的运算符:特征向量是指向该方向的向量不会被矩阵扭曲的特殊方向,特征值是衡量矩阵扩展或收缩向量多少的因素.
and so they're actually the same eigenvectors. Think of the matrix as an operator which changes a vector: the eigenvectors are the special directions where a vector pointing that way won't be twisted by the matrix, and the eigenvalues are the factors measuring how much the matrix expands or contracts the vector.
这篇关于Matlab VS Python - eig(A,B) VS sc.linalg.eig(A,B)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!