I am having a huge problem with my Mathematica notebook.
I am trying to evaluate LUDecomposition
and it keeps getting wrong - when I multiply l
and u
, I get my A
matrix, but the first row is displayed as the last. I have no idea how to fix it...
My A matrix looks like this:
A = {{3, 2, 0, 0, 0, 0, 0, 0, 0}, {2, 8, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 4, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 3, 2, 0, 0, 0, 0}, {0, 0, 0, 2, 4, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 5, 2, 0, 0}, {0, 0, 0, 0, 0, 2, 3, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 8, 2}, {0, 0, 0, 0, 0, 0, 0, 2, 4}};
What I do is:
{lu, p, c} = LUDecomposition[A];
l = LowerTriangularize[lu, -1] + IdentityMatrix[Length[p]];
u = UpperTriangularize[lu];
P = Part[IdentityMatrix[Length[p]], p];
MatrixForm /@ {P.A, P, l, u, l.u};
And I get:
The last one should equal my A
matrix, but obviously it does not. It seems like the first row is the last one. Do you have any idea why? I will be very grateful for any kind of help because it is getting me really crazy.
l.u
goes by the permutation of the rows done. So you need to considerp
as well. $\endgroup$