为什么当我尝试将对称矩阵对角线化时,为什么不是t`np.linalg.eig返回统一矩阵?

发布于 2025-02-05 17:55:28 字数 1894 浏览 3 评论 0原文

使用Python,我创建了一个对称矩阵x,并使用代码lambda,u = np.linalg.eig(x)对对角线化。我的理解是:由于x是对称的,u应该是统一的,但我发现事实并非如此,因为u具有eigenvalues这没有绝对值1,这也意味着这也不是缩放问题。我的问题是为什么u不统一?


这是一个最小可重现的示例,可以查看我得到的内容:

import numpy as np

#Symmetric matrix, which should be diagonalized by unitary
X = np.array([[-1.1918157 ,  0.        ,  0.        ,  0.        ,  0.09852097,
         0.        ,  0.        ,  0.        ],
       [ 0.        , -1.1918157 ,  0.        ,  0.        ,  0.        ,
         0.09852097,  0.        ,  0.        ],
       [ 0.        ,  0.        , -1.08529969,  0.        ,  0.        ,
         0.        ,  0.07826825,  0.        ],
       [ 0.        ,  0.        ,  0.        , -1.08529969,  0.        ,
         0.        ,  0.        ,  0.07826825],
       [ 0.09852097,  0.        ,  0.        ,  0.        , -1.00585682,
         0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.09852097,  0.        ,  0.        ,  0.        ,
        -1.00585682,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.07826825,  0.        ,  0.        ,
         0.        , -0.98276093,  0.        ],
       [ 0.        ,  0.        ,  0.        ,  0.07826825,  0.        ,
         0.        ,  0.        , -0.98276093]])

#check if X is symmetric
assert np.linalg.norm(X - X.conj().T) == 0

#diagonalize X
Lambda, U = np.linalg.eig(X)

#check if U is unitary
print(
    np.allclose(U @ U.conj().T, np.identity(U.shape[0])),
    np.allclose(U.conj().T,     np.linalg.inv(U))
)

#Since the above returns false, how non-unitary is it?
print(
    np.linalg.norm(U @ U.conj().T - np.identity(U.shape[0])),
    np.linalg.norm(U.conj().T - np.linalg.inv(U))
)

上述代码的输出是:

False False
0.994793051566498 1.1641788210519939

Using Python, I created a symmetric matrix X, and diagonalized it using the code Lambda, U = np.linalg.eig(X). My understanding is: since X is symmetric, U should be unitary, but I am finding that this is not the case, as U has eigenvalues that don't have absolute value 1, which also means that this is not a scaling issue either. My question is why is U not unitary?


Here is a minimum reproducible example to see what I am getting:

import numpy as np

#Symmetric matrix, which should be diagonalized by unitary
X = np.array([[-1.1918157 ,  0.        ,  0.        ,  0.        ,  0.09852097,
         0.        ,  0.        ,  0.        ],
       [ 0.        , -1.1918157 ,  0.        ,  0.        ,  0.        ,
         0.09852097,  0.        ,  0.        ],
       [ 0.        ,  0.        , -1.08529969,  0.        ,  0.        ,
         0.        ,  0.07826825,  0.        ],
       [ 0.        ,  0.        ,  0.        , -1.08529969,  0.        ,
         0.        ,  0.        ,  0.07826825],
       [ 0.09852097,  0.        ,  0.        ,  0.        , -1.00585682,
         0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.09852097,  0.        ,  0.        ,  0.        ,
        -1.00585682,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.07826825,  0.        ,  0.        ,
         0.        , -0.98276093,  0.        ],
       [ 0.        ,  0.        ,  0.        ,  0.07826825,  0.        ,
         0.        ,  0.        , -0.98276093]])

#check if X is symmetric
assert np.linalg.norm(X - X.conj().T) == 0

#diagonalize X
Lambda, U = np.linalg.eig(X)

#check if U is unitary
print(
    np.allclose(U @ U.conj().T, np.identity(U.shape[0])),
    np.allclose(U.conj().T,     np.linalg.inv(U))
)

#Since the above returns false, how non-unitary is it?
print(
    np.linalg.norm(U @ U.conj().T - np.identity(U.shape[0])),
    np.linalg.norm(U.conj().T - np.linalg.inv(U))
)

The output of the above code is:

False False
0.994793051566498 1.1641788210519939

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2025-02-12 17:55:28

永远无法保证返回统一矩阵。

#diagonalize X
Lambda, U = np.linalg.eig(X)

从这一行代码中,您可以找到x的特征值(存储在lambda中)及其右eigenVectors (存储在矩阵中u中)。参见 doc

这里唯一的统一事物是特征向量,它是u

In [4]: np.linalg.norm(U, axis=0)
Out[4]: array([1., 1., 1., 1., 1., 1., 1., 1.])

阅读有关特征值和特征向量的更多信息: wolfram

It's never guaranteed to return a unitary matrix.

#diagonalize X
Lambda, U = np.linalg.eig(X)

From this line of code, you are finding eigenvalues of X (stored in Lambda) and its right eigenvectors (stored in matrix U). See the doc.

The only unitary things here are the eigenvectors, which are the columns of U.

In [4]: np.linalg.norm(U, axis=0)
Out[4]: array([1., 1., 1., 1., 1., 1., 1., 1.])

Read more about eigenvalues and eigenvectors: wiki, wolfram

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文