I am trying to find the polar decomposition of a matrix.I tried studying it from a video lecture : https://www.youtube.com/watch?v=VjBEFOwHJooI tried implementing the way they have done, trusting their calculations of Eigen values and Eigen vectors as shown below and it gives correct value of U
and P
matrix.
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 vectorsy = np.array([[25,0,0],[0,225,0],[0,0,2025]]) # Eigen valuesz = np.linalg.inv(np.array([[-1,1,1],[0,-2,1],[1,1,1]])) # Inverse Eigen vectorsA_transpose_A = x @ y @ zprint("A transpose A by multiplying Eigen vectors, Eigen values and Inv of Eigen vectors")print(A_transpose_A) P = x @ np.sqrt(y) @ zprint("Matrix P")print(P)U = A @ np.linalg.inv(P)print("Matrix U")print(U)
But when I try to implement the Eigen vectors and Eigen values using the API from numpy, the thing do not match:
import numpy as np# Define the matrixA = np.array([[4,-14,1], [22,23,18], [15,10,20]])A_T_multiply_A = np.array(A.T @ A)# Compute eigenvalues and eigenvectorseigenvalues, eigenvectors = np.linalg.eig(A_T_multiply_A)# Print the resultsprint("Eigenvalues:")print(eigenvalues)print("\nEigenvectors:")print(eigenvectors)
Not sure why I am getting this difference?It would be great if someone can explain me this or provide me some good link.
The values of Eigen values and Eigen vectors I got using 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]]
Also, providing the python code for calculating polar decomposition using a numpy API.
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)
The result is:
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.]]