Hello,
My apologies if the question sounds too trivial but I am new to LAPACK and can't figure out what's going wrong with the code. Ok, so here it goes.
I need to solve for x in Ax = b system where the matrix A (about 100 x 100 size ) is square,( but could also be rectangular sometimes ), complex, dense, and highly ill-conditioned (condition number \kappa ~ 10E+017 ). The best way to solve such a system is obviously SVD.
First I computed the SVD using Matlab, then obtained the inverse of A to get solution vector x ( A^{-1} b ) and that gives me the correct answer ( I am solving a problem for which theoretical solution is available).
But when I tried to solve the same problem with ZGESVD, I get a wrong solution. Wrong decomposition? Obviously! Yes, the matrix entries for U and V from ZGESVD and MATLAB ([u,s,v] = svd(A)) are very different. Only a few entries from upper left corner of U and V match (that too only upto 4 or 5 deciamal places). Surprisingly, I get a very good comparison between ZGESVD and Matlab for singular vector S.
When I test the ZGESVD code for a small matrix with a reasonable \kappa (~ 10E+001 ) ( a randomly generated matrix from Matlab ), the comparison is very good for U, V and S (the numbers match to double precision ). I am not sure what goes wrong when I try this with a bigger and highly ill-conditioned complex matrix using ZGESVD.
I checked for the correctness of the input that is given to ZGESVD (precision, sequence of arguments etc. ), everything looks OK. Not sure why I can’t get the correct SVD from ZGESVD when Matlab uses same routine for its SVD command. Is there anything I am missing?
Just for the sake of completeness – I use gfortran compiler ( from minGW ) with LAPACK libraries built using CMAKE.
I compile and link the libraries as follows:
gfortran -g -c *.f95
gfortran -o main *.o liblapack.a libblas.a
Thanks in advance for any help/comments/suggestions.

