2

I want to compute the determinant of a matrix from its LUP decomposition in MATLAB. The determinant can be found from the formula:

enter image description here

P is a permutation matrix and S is the number of exchanges of rows needed to transform P into an identity matrix. How can I find S in the above formula in MATLAB? Does it have any pre-defined functions, etc.?

user215721
  • 299
  • 2
  • 11

1 Answers1

3

If you interpret P as an adjacency matrix, and the vector cycles contains the length of all cycles in the graph described by P, then S=sum(cycles) - length(cycles).

Now all is left is to find the length of all the cycles, for which there are several functions on the File Exchange, like this one.

BTW: [L, U, P] = lu(A), and det(A) = det(inv(P))*det(L)*det(U)

Jonas
  • 74,690
  • 10
  • 137
  • 177