I'm trying to get the determinant of a matrix by LU factorization.
I have the following matrix:
a = [2 4 2;
1 5 2;
4 -1 9];
When I execute the command det(a) in matlab, it shows the determinant to be 48. Then I enter the decomposition command:
[L, U, P] = lu(a)
It shows the matrix L to be:
1.0000 0 0
0.2500 1.0000 0
0.5000 0.8571 1.0000
and the matrix U to be:
4.0000 -1.0000 9.0000
0 5.2500 -0.2500
0 0 -2.2857
As we know that the determinant of a matrix is also the product of the principal diagonal elements of it's U matrix after the decomposition, it doesn't match up in this case. Because the product of the diagonal elements of the matrix U is -47.999. But it shouldn't have been a negative number.
What am I missing here?
$$LU=PA$$
$$\det(L) \det(U) = \det(P) \det(A)$$
$$\det(A) = \det(P) \det(U)$$
since $\det(L)=1$.
$\det(P)=-1$ for this example.