How to find the determinant of a matrix using the PA = LU method.

$\begingroup$

I am currently trying to write a code in matlab for a course I'm taking. My program needs to implement the PA = LU method to solve a matrix and compute it's determinant. I am not allowed to use the lu(A) or any other built in functions. So far I managed to write the code required to find the matrices P,L,U given matrix A, but I ran into trouble when it came time to compute the determinant.

Since the PA = LU method uses pivoting, the determinant should be the same as the A = LU method, but might be of different sign depending on how many pivoting has been performed. My question is, how can I figure the determinant from the P,L,U matrices? I know that for the A = LU method, the determinant is det(A) = det(L)*det(U), where det(L) = 1, which gives us det(A) = det(U). det(U) is simply the product of it's diagonal elements, which is fairly easy to compute. But in the case of PA = LU, we have det(P)*det(A) = det(L)*det(U). To solve for det(A) I need to find det(P), which I don't know how to compute in an efficient way. I know that det(P) can either be 1 or -1, but given an NxN permutation matrix, how can I figure that out efficiently? I tried to search it on google but I couldn't find anything relevant. I am not asking for the matlab code but for a method to compute a permutation matrix determinant or at the very least figure how many row swaps have been performed from the permutation matrix if that is possible. Thank you.

$\endgroup$

1 Answer

$\begingroup$

$PA=LU$ and $\det(P)=+1$ or $-1$ depending on the sign of the permutation, so $\det(A)=\det(L)\det(U)\det(P)$. So if $L$ only has $1$'s on the diagonal, $\det(L)=1$ and so you just have to compute $\det(U)$ which is easy (product of diagonal). The $\det(P)$ is easy: start with $p=1$ and with every (row or column) swap (during the $LU$ computation), multiply $p$ by $-1$. The final $p$ is what you need. It's an almost free byproduct.

$\endgroup$ 3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like