Reputation: 317
I want to compute the determinant of a matrix from its LUP decomposition in MATLAB. The determinant can be found from the formula:
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.?
Upvotes: 2
Views: 777
Reputation: 74940
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)
Upvotes: 3