lu
LU factorization of a matrix.
Category: Mathematics > Linear Algebra
Syntax
[L, U] = lu(A)
Returns a permuted lower triangular L and upper triangular U with L*U = A.
[L, U, P] = lu(A)
Returns L truly lower triangular and a permutation matrix P with P*A = L*U.
[L, U, p] = lu(A, 'vector')
Returns the permutation as a row vector p, with A(p,:) = L*U.
Y = lu(A)
Returns the packed factors in one matrix.
Description
Gaussian elimination written as a matrix product. The rows are swapped so that each pivot is the largest available in its column (partial pivoting), which keeps the multipliers at most 1 in size and the method stable.
Once factored, a system A*x = b is solved with two triangular solves, cheap for repeated right-hand sides. det(A) follows from the diagonal of U and the sign of the permutation.
Input arguments
A- Matrix, usually square.
Output arguments
L, U- Lower and upper triangular factors;
Lhas unit diagonal. P, p- Row permutation as a matrix or as an index vector.
Example
With a permutation matrix
A = [4 3; 6 3];
[L, U, P] = lu(A)
disp(norm(P*A - L*U) < 1e-12)
Output
L = 2×2
1.0000 0
0.6667 1.0000
U = 2×2
6 3
0 1
P = 2×2
0 1
1 0
1