Julia SVD results differing from MATLAB

I’ve been scratching my head about this for some time now and thought of asking to see if anyone has a fix for this. I am converting a code from MATLAB into Julia and it requires the use of svd and eig multiple times. I converted it line by line and then when I finally ran it, I noticed some large differences in results.

After attempting to troubleshoot and pin down where the differences stem from, I believe it to be the svd function from Julia, which calls LinearAlgebra.LAPACK.gesdd!.

The reason I have pointed it down to svd is because of the singular values obtained. In MATLAB I get positive-negative pairs, however in Julia, I don’t receive the same symmetry, but the results should be symmetrical.

I’ve tried to find how to decrease the tolerance of this function (ie make it slower but hopefully more accurate) to see if this is the issue, but there is no documentation at all about running gesdd or gesvd with changed internal tolerances (as far as I can tell, I am however quite new to Julia and LAPACK so I may just not be looking in the right place).

So I guess my question is: Is there a way to increase the precision, whether it be from the svd, gesvd/gesdd?

Some resources I have used but did not help:
1
2

Any help would be appreciated,

Thanks,
Daniel.

From your first link, have you tried svd(A, alg=QRIteration())? For these sorts of questions, it really helps to include a minimal working example that reproduces the behavior you’re seeing.

3 Likes

The reason I have pointed it down to svd is because of the singular values obtained. In MATLAB I get positive-negative pairs, however in Julia, I don’t receive the same symmetry, but the results should be symmetrical.

How do you get positive-negative pairs for the singular values? Aren’t they all non-negative?

6 Likes

It would be best if you could give us a matrix that demonstrates the problem. Either just dump it inside one of your functions with DelimitedFiles.writedlm.

2 Likes

Can this post please be deleted. I realised I have not asked/formatted it properly and believe the issue to be with the original code I was trying to convert.

Thank you for your help to the commenters

I am happy to hear that you solved your problem.

However, I don’t think that posts like this should be deleted. Rather, you should mark a solution, so that people encountering a similar problem are encouraged to repeat what you did (here, specifically, look at their code carefully and create an MWE).

5 Likes