[TOC]

lu

LU decomposition

Introduction

In the following, is either (real) or (complex). If is non-singular, there exists a unique decomposition

where is a unit lower triangular matrix and is an upper triangular matrix.

💡 A unit triangular matrix has all of its diagonal elements equal to 1, i.e., .

Let be a rectangular matrix and . If the first principle leading submatrices are nonsingular, there exists the decomposition

where is a unit lower triangular matrix and is an upper triangular matrix.

The matrix can be permuted before factorisation to improve stability. Let be a given (real) permutation matrix. Then, it holds that

where is the transpose of .

Usages

Y = lu(A)

Y = lu(A, perm)

[PtL, U] = lu(A)

[PtL, U] = lu(A, perm)

[L, U, P] = lu(A)

[L, U, P] = lu(A, 'matrix')

[L, U, e] = lu(A, 'vector')

Examples

Input
% Randomly generated matrix
a = randi(10,4,5);

% P contains permutation information
[L,U,e] = lu(a,'vector');

% Construct a permuation matrix Q using e
Q = zeros(size(a,1));
for r = 1:size(a,1)
    Q(r,e(r)) = 1;
end

% Permutation matrix T given by lu with type equal to 'matrix'
[L,U,T] = lu(a,'matrix');

% Permutation matrices Q and T are the same
Q
T
Output
Q =
 0.000   0.000   0.000   1.000
 1.000   0.000   0.000   0.000
 0.000   0.000   1.000   0.000
 0.000   1.000   0.000   0.000

T =
 0.000   0.000   0.000   1.000
 1.000   0.000   0.000   0.000
 0.000   0.000   1.000   0.000
 0.000   1.000   0.000   0.000
Input
A = randi(10,3,5);
[L,U,P] = lu(A);
Y = lu(A);
L
U
Y
Output
L =
 1.000   0.000   0.000
 0.700   1.000   0.000
 0.600  -0.235   1.000

U =
 10.00   7.000   6.000   5.000   8.000
 0.000   5.100   3.800   3.500  -0.600
 0.000   0.000  -0.706   6.824  -3.941

Y =
 10.00   7.000   6.000   5.000   8.000
 0.700   5.100   3.800   3.500  -0.600
 0.600  -0.235  -0.706   6.824  -3.941
Input
% Generate a random matrix
A = rand(6,4);

% LU decomposition
[L,U] = lu(A);

% L*U and A are (apprxoimately) identical
L*U-A
Output
ans = 1e-16 × 
 0.000   1.110   1.110   0.278
 1.110   0.000   0.000   0.000
 0.069   0.000   0.000  -0.278
 0.000  -0.278   0.000   0.000
 0.000   0.000   0.000   0.000
 0.000   0.555  -0.278   0.000