In the armadillo library, the Lu decomposition (LU factorisation or Lu decomposition) of the matrix uses the Lu function. The Lu function has two versions.
1 Lu (L, U, P, X)
X is the matrix to be decomposed to generate L, U, and P.
1) P is a permutation matrix, so the inverse of P is equal to its transpose (transpose)
2) L is a unit of lower Triangle Matrix (unit lower triangular matrix)
3) U is a strict upper triangular matrix)
4) Px = LU, that is, ptlu = x
Example:
mat m = "2,4,2;1,5,2;4,-1,9;";mat l, u, p;lu(l, u, p, m);cout << "L:" << endl;l.print();cout << "U:" << endl;u.print();cout << "P:" << endl;p.print();
Running result:
2 Lu (L, U, X)
X is the matrix to be decomposed to generate L, and u meets
1) U is a strict upper triangular matrix)
2) x = Lu
Due to the algorithm, the L generated by decomposition using this function is generally not of the lower triangle.
Example:
mat m = "2,4,2;1,5,2;4,-1,9;";mat l, u;lu(l, u, m);cout << "L:" << endl;l.print();cout << "U:" << endl;u.print();
Running result:
NOTE: If matrix X cannot be decomposed, the Lu function returns false and clears the L, U, and P matrices. Returns true if the decomposition is successful.