title: QR factorization from lapack subroutine dgeqrf not working in C
body: <p>I want to find diagonal elements of R matrix obtained from QR-decomposition of A matrix as A=QR using lapack. I tried lapack dgeqrf subroutine but it is giving back the same matrix A i.e. input and output matrices are same. How to find R matrix and its diagonals ? I can't figure out what is going wrong with this code. I am programming in C.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  void dgeqrf_(int *rows, int *cols, double *matA, int *LDA, double *TAU, double *WORK, int *LWORK, int *INFO);
  int main()
  {
      int rows=3;
      int cols=3;
      double *matA=malloc(sizeof(double)*rows*cols);
  
      matA[0]=10;
      matA[1]=20;
      matA[2]=10;
      matA[3]=40;
      matA[4]=20;
      matA[5]=50;
      matA[6]=70;
      matA[7]=30;
      matA[8]=20;
  
      for(int i=0; i&lt;rows*cols; i++)
      {
          printf("%f ",matA[i]);
      }
      printf("\n");
      int LDA=rows;
      int INFO;
      double *WORK=malloc(sizeof(double)*2);
      int LWORK=-1;
      int rowcolmin=rows;
      if(rowcolmin&gt;cols)
      {
          rowcolmin=cols;
      }
      double *TAU=malloc(sizeof(double)*rowcolmin);
      dgeqrf_(&amp;rows, &amp;cols, matA, &amp;LDA, TAU, WORK, &amp;LWORK, &amp;INFO);
      for(int i=0; i&lt;rows*cols; i++)
      {
          printf("%f ",matA[i]);
      }
      printf("\n");
      free(WORK);
      free(TAU);
      free(matA);
      return 0;
  }
  </code></pre>