Qianyong Chen, I think the segfault was because lwork was too small; doing as follows doesn't seem to crash matlab. The fortranError as well as fortranError_SVD remain both numerically zero.
A = rand(118,106);
% 1st: results from direct matlab
[UM, SM, VM] = svd(A);
matlabError = max(max(abs(A-UM*SM*VM')))
% 2nd: results when using 'lapack' by Tim Toolan
[m,n] = size(A);
Dude, your code rocks! You're awesome! :) I have been able to use the dsyev routine on a very large matrix (size 200k^2). It actually worked just as well, if not better, than Matlab 2011b's eig.
28 Nov 2011
lapack
Easily call any LAPACK or BLAS routine from inside Matlab.
Author: Tim Toolan
I really like this idea. But couldn't make it work on my machine: 64bit Win7 with SDK 7.1 with Matlab 2011b.
The first run is always fine. But when I run the same code a few more times, it either stops due to segmentation error,
or gives unreliable results. Also, the difference for U and V (between Matlab results and using lapack.c provided here)
is large when the matrix is as small as 118 by 106. The error for the matrix itself (A - U * S * V) is very small though.
What I did is: 1) compile with mex lapack.c
2) run the following code:
% test a couple subroutines
clear all;
%--------------------
%1st: dgesvd.f
%--------------------
A = rand(118,106);
% 1st: results from direct matlab
[UM, SM, VM] = svd(A);
matlabError = max(max(abs(A-UM*SM*VM')))
% 2nd: results when using 'lapack' by Tim Toolan
[m,n] = size(A);