I'm computing a LU-Factorization with Lapack and compare the results. I use either dgetrf or dgetf2. Comparing the results to the corresponding function lu(...) in Matlab, they are identical as long as the the input matrix is square or has more columns than rows. For matrixes with more rows than columns, the values at the bottom right lu-matrix differ. For example, dgetrf and dgetf2 in Lapack for
A=[
1 2 3;
4 5 6;
7 8 9;
10 11 12]
gives
lu = [
10.0 11.0 12.0;
0.1 0.9 1.8;
0.7 0.33333 0.0;
0.4 0.66666 0.45989304812834225]
but the same calculated in Matlab results in
lu = [
10.0 11.0 12.0;
0.1 0.9 1.8;
0.7 0.33333 0.0;
0.4 0.66666 0.0]
I have no clue, where difference in the last value of the last row comes from. The same effect is present, when having even more rows. I'm using Lapack in Swift, but I don't think it has anything to do with the programming language. Any clue? Your help is appreciated.
I've tried varying the input parameters of dgetrf and dgetf2, but still the same effect.
I wrote some MATLAB m-code to test this on my win PC running R2021a. I also wrote C-code to call the MATLAB LAPACK library directly for dgetrf( ) and dgetf2( ). Here is what I get for results:
So the MATLAB lu( ) function produces the same result as calling the MATLAB LAPACK library functions dgetrf( ) and dgetf2( ) directly, and they all have that lower right corner spot filled. Maybe you can compare your code to my code below to help determine what is going wrong at your end.
The m-code:
The C-code for dgetrf:
The C-code for dgetf2:
The mex compile routine:
To compile the mex routines:
UPDATE -----------------------------------------------------------
Online MATLAB R2023a gives these results:
So there does appear to be a somewhat recent change in the LU algorithm used that gives an exact 0 for the U(3,3) and L(4,3) spots. Whereas my PC MATLAB R2021a gives:
Yes, it looks funny, but both answers are "correct" in the sense that these residual values are within what one might expect from simple floating point numerical effects.
Feedback on the MATLAB Answers forum indicates that this change may have occurred in the R2022a release.