Search code examples
c++lapack++

How to calculate determinant matrix with lapack++ (2.5+)


What is the best (fastest) way to calculate the determinant of a (non symmetric, squared) LaMatGenDouble matrix with the lapack++ library?


Solution

  • One way to calculate the determinant is using the LU decomposition:

      LaVectorLongInt pivots(A.cols());
    
      LUFactorizeIP(A, pivots);
    
      double detA = 1;
      for (int i = 0; i < A.cols(); ++i)
        detA *= A(i, i);
    

    Warning, A will change, so making a copy is probably advised.