I did a error while understanding about the polar decompositon.
I thought polar decomposition is PU, but it is UP. While trying to understand what went wrong, I realized that it is somewhat commutative for the inputs I am giving to it because of which I could not realize about this big mistake.
It would be great if someone can explain about this so that I can understand whether it is commutative for all diagonal matrices?
Are there any polar decompositon formula where polar decomposition is PU? Thank you for great help.
import numpy as np
from scipy.linalg import polar
A= np.array([[-2, 1, 0, 0],
[1, -2, 1, 0],
[0, 1, -2, 1],
[0, 0, 1, -2]])
U, P = polar(A)
print(U)
print(P)
A1 = U @ P
print(A1)
A2 = P @ U
print(A2)
are_equal = np.allclose(A1, A2)
print("Are matrix equal:", are_equal)