I am trying to use Singular Value Decomposition algorithm from numpy library (numpy-MKL-1.6.2.win-amd64-py2.7), but I propose that this function doesn’t correct. This function has the following statement:
from numpy.linalg import *
U, S, V = svd(A, full_matrices=0)
My assumption is based on comparison comparison with the same function in Matlab, which gives a correct answer. I also found that the problems related to the wrong calculation of V matrix.
For example, I have matrix A:
A =[-15.5714, 19.2143, 15.0000; -2.8462, 7.7692, -3.9615; -19.5000, 3.1111, 4.5556]
In python I receive:
V = [0.7053, -0.5629, -0.4308; -0.6863, -0.6945, -0.2161; -0.1776, 0.4481, -0.8762]
and in Matlab:
V = [0.7053, -0.6863, -0.1776; -0.5629, -0.6945, 0.4481; -0.4308, -0.2161, -0.8762]
Differences are not so evident, but they become critical during LLS calculations.
How can I overcome this problem?
OK, I found the answer:
[U,S,V]=svd(a) – Matlab
U, S, Vh = linalg.svd(a), V = Vh.T – Python
Maybe my question helps someone in future.
Your Matlab
Vmatrix and numpyVmatrix are transposes of each other.You can use the transpose() function to obtain the transposed version.