求矩阵的极分解

问题描述 投票:0回答:1

我正在尝试找到矩阵的极分解。 我尝试通过视频讲座来学习它:https://www.youtube.com/watch?v=VjBEFOwHJoo 我尝试实现他们所做的方式,相信他们对特征值和特征向量的计算,如下所示,它给出了正确的

U
P
矩阵值。

A = np.array([[4,-14,1],[22,23,18],[15,10,20]])
A_T_multiply_A = np.array(A.T @ A)
print("A transpose into A")
print(A_T_multiply_A)


x = np.array([[-1,1,1],[0,-2,1],[1,1,1]])           # Eigen vectors
y = np.array([[25,0,0],[0,225,0],[0,0,2025]])      # Eigen values
z = np.linalg.inv(np.array([[-1,1,1],[0,-2,1],[1,1,1]]))    # Inverse Eigen vectors
A_transpose_A = x @ y @ z
print("A transpose A by multiplying Eigen vectors, Eigen values and Inv of Eigen vectors")
print(A_transpose_A)  
P  = x @ np.sqrt(y) @ z
print("Matrix P")
print(P)
U = A @ np.linalg.inv(P)
print("Matrix U")
print(U)

但是当我尝试使用 numpy 中的 API 实现特征向量和特征值时,事情不匹配:

import numpy as np

# Define the matrix
A = np.array([[4,-14,1],
              [22,23,18],
              [15,10,20]])
A_T_multiply_A = np.array(A.T @ A)

# Compute eigenvalues and eigenvectors
eigenvalues, eigenvectors = np.linalg.eig(A_T_multiply_A)

# Print the results
print("Eigenvalues:")
print(eigenvalues)

print("\nEigenvectors:")
print(eigenvectors)

不确定为什么会出现这种差异? 如果有人可以向我解释这一点或为我提供一些好的链接,那就太好了。

我使用 numpy 得到的特征值和特征向量的值:

   Eigenvalues:
[2025.   25.  225.]

Eigenvectors:
[[-5.77350269e-01 -7.07106781e-01  4.08248290e-01]
 [-5.77350269e-01 -3.91901695e-16 -8.16496581e-01]
 [-5.77350269e-01  7.07106781e-01  4.08248290e-01]]

此外,还提供使用 numpy API 计算极分解的 python 代码。

    import numpy as np
    from scipy.linalg import polar
    A = np.array([[4,-14,1],[22,23,18],[15,10,20]])
    U, P = polar(A)
    print("Matrix U=")
    print(U)
    print("Matrix P=")
    print(P)

结果是:

Matrix U=
[[ 6.00000000e-01 -8.00000000e-01  2.40023768e-16]
 [ 8.00000000e-01  6.00000000e-01  3.21346710e-16]
 [ 2.32191141e-16  6.61562711e-17  1.00000000e+00]]
Matrix P=
[[20. 10. 15.]
 [10. 25. 10.]
 [15. 10. 20.]]
python numpy svd decomposition
1个回答
0
投票

这是使用

svd
的解决方案:

将 numpy 导入为 np

vecU, vals, vecV = np.linalg.svd(A)

P = vecV.T @ np.diag(vals) @ vecV
U = vecU @ vecV

P
array([[20., 10., 15.],
       [10., 25., 10.],
       [15., 10., 20.]])

U
array([[ 6.00000000e-01, -8.00000000e-01,  5.73090676e-16],
       [ 8.00000000e-01,  6.00000000e-01,  3.76857861e-16],
       [ 2.32191141e-16, -5.92653245e-17,  1.00000000e+00]])

np.round(U, 8)
array([[ 0.6, -0.8,  0. ],
       [ 0.8,  0.6,  0. ],
       [ 0. , -0. ,  1. ]])

将结果与您的结果进行比较,您会发现它们是相同的

© www.soinside.com 2019 - 2024. All rights reserved.