Hello,
I'm having some unexpected results with the function LAPACKE_dgeqrf. Apparently I'm unable to get the appropriate QR decomposition at some cases, I'm rather obtaining a QR decomposition with some unexpected vector orientations for the orthogonal matrix Q.
Here is a MWE of the problem:
#include <stdio.h> #include <stdlib.h> #include "mkl.h" #define N 2 int main() { double *x = (double *) malloc( sizeof(double) * N * N ); double *tau = (double *) malloc( sizeof(double) * N ); int i, j; /* Pathological example */ x[0] = 4.0, x[1] = 1.0, x[2] = 3.0, x[3] = 1.0; printf("\n INITIAL MATRIX\n\n"); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { printf(" %3.2lf\t", x[i*N+j]); } printf("\n"); } LAPACKE_dgeqrf ( LAPACK_ROW_MAJOR, N, N, x, N, tau); printf("\n R MATRIX\n\n"); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if ( j >= i ){ printf(" %3.2lf\t", x[i*N+j]); }else{ printf(" %3.2lf\t", 0.0); } } printf("\n"); } LAPACKE_dorgqr ( LAPACK_ROW_MAJOR, N, N, N, x, N, tau); printf("\n Q MATRIX\n\n"); for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { printf(" %3.2lf\t", x[i*N+j]); } printf("\n"); } printf("\n"); return 0; }
With this example, the output I get is:
INITIAL MATRIX
4.00 1.00
3.00 1.00
R MATRIX
-5.00 -1.40
0.00 0.20
Q MATRIX
-0.80 -0.60
-0.60 0.80
However, the expected QR decomposition would be:
R MATRIX
5.00 1.40
0.00 0.20
Q MATRIX
0.80 -0.60
0.60 0.80
I have found this problem with other Initial matrices as well.
Thanks in advance,
Paulo