Matrix Squareroot Using Single Value Decomposition (SVD)

581 Views Asked by At

I'm trying to find the square root of a square matrix(real or complex) that can have complex eigenvalues and eigenvalues. The approach that I'm using requires me to first calculate the Eigenvalues and the Eigenvectors. For this purpose, I'm using LAPACK's zgeev. I get the correct eigens using this routine.

$$A = \begin{bmatrix}1 & -2 \\ 3 & 4\end{bmatrix}$$

by applying LAPACK's zgeev i get eigens as

$$eigenValues = \begin{bmatrix}2.5+1.9365i \\ 2.5-1.9365i\end{bmatrix} eigenVectors=\begin{bmatrix}-0.3873+0.5i & -0.3873-0.5i\\ 0.7746+0i&0.7746+0i\end{bmatrix}$$

Now we know that the square root of the matrix can be calculated as $$PD^{1/2}P^{-1}$$

Where P is the eigenVectors and D is eigenValues.

The $P^{-1}$ is not the inverse but the Pseudo Inverse that I'm trying to calculate. Now to calculate the Pseudo Inverse of the matrix P, I'm using the Single Value Decomposition. For this purpose, I'm using LAPACK's zgesvd routine that returns back 3 matrices commonly known as USV

$$U = \begin{bmatrix}-0.5532+0.1892i & 0.7676-0.2625i \\ 0.2625+0.7676i & 0.1892+0.5532i\end{bmatrix} S=\begin{bmatrix}1.2777 \\ 0.6063\end{bmatrix} \\ V = \begin{bmatrix}0.7071+0i & 0.7071+0i \\ 0.5590+0.433i & -0.5590-0.4330i\end{bmatrix}$$

Problem: The V matrix that comes from LAPACK contains exact values as of Matlab's SVD but the signs are different. $$LAPACK's\_V = \begin{bmatrix}0.7071+0i & 0.7071+0i \\ 0.5590+0.433i & -0.5590-0.4330i\end{bmatrix} \\ Matlab's\_V = \begin{bmatrix}0.7071+0i & 0.7071+0i \\ 0.5590-0.433i & -0.5590+0.4330i\end{bmatrix}$$

I have tested this on python as well. I'm using Scipy's Linear Algebra module and the V that I get from Scipy's SVD also matches the V of LAPACK. Matlab's SVD is different however but the correct one as it gives me accurate results.

Now I have created the whole pipeline that calculates the Pseudo Inverse using SVD and then I can calculate the Matrix Squareroot using Python, Matlab, and Swift but due to the sign ambiguity in this only matrix V, my results become inconsistent in Python and Swift. But for Matlab, if I follow the exact steps, I get the perfect square root. I have done multiple tests and have come to the conclusion that the root cause of incorrect results is the sign problem in matrix V of Scipy or Swift(LAPACK).

Questions

  1. Please guide me that why is V different? As far as my knowledge goes, Matlab also uses LAPACK at the backend.
  2. What is the most straightforward way to fix this issue?
  3. Is there any other approach to calculate matrix square root or at least the Pseudo Inverse?

I'm very close to solve this square root problem. I just need to fix V.

1

There are 1 best solutions below

0
On

Taking the complex conjugate for the matrices U and V resolved the problem for me. I'm able to calculate the Squareroot of the matrix perfectly.