Documentation |
LU factorization
[L,U] =
lu(A)
[L,U,P]
= lu(A)
[L,U,p]
= lu(A,'vector')
[L,U,p,q]
= lu(A,'vector')
[L,U,P,Q,R]
= lu(A)
[L,U,p,q,R]
= lu(A,'vector')
lu(A)
[L,U] = lu(A) returns an upper triangular matrix U and a matrix L, such that A = L*U. Here, L is a product of the inverse of the permutation matrix and a lower triangular matrix.
[L,U,P] = lu(A) returns an upper triangular matrix U, a lower triangular matrix L, and a permutation matrix P, such that P*A = L*U.
[L,U,p] = lu(A,'vector') returns the permutation information as a vector p, such that A(p,:) = L*U.
[L,U,p,q] = lu(A,'vector') returns the permutation information as two row vectors p and q, such that A(p,q) = L*U.
[L,U,P,Q,R] = lu(A) returns an upper triangular matrix U, a lower triangular matrix L, permutation matrices P and Q, and a scaling matrix R, such that P*(R\A)*Q = L*U.
[L,U,p,q,R] = lu(A,'vector') returns the permutation information in two row vectors p and q, such that R(:,p)\A(:,q) = L*U.
lu(A) returns the matrix that contains the strictly lower triangular matrix L (the matrix without its unit diagonal) and the upper triangular matrix U as submatrices. Thus, lu(A) returns the matrix U + L - eye(size(A)), where L and U are defined as [L,U,P] = lu(A). The matrix A must be square.
A |
Square or rectangular symbolic matrix. |
'vector' |
Flag that prompts lu to return the permutation information in row vectors. |
Compute the LU factorization of this matrix. Because these numbers are not symbolic objects, you get floating-point results.
[L, U] = lu([2 -3 -1; 1/2 1 -1; 0 1 -1])
L = 1.0000 0 0 0.2500 1.0000 0 0 0.5714 1.0000 U = 2.0000 -3.0000 -1.0000 0 1.7500 -0.7500 0 0 -0.5714
Now convert this matrix to a symbolic object, and compute the LU factorization:
[L, U] = lu(sym([2 -3 -1; 1/2 1 -1; 0 1 -1]))
L = [ 1, 0, 0] [ 1/4, 1, 0] [ 0, 4/7, 1] U = [ 2, -3, -1] [ 0, 7/4, -3/4] [ 0, 0, -4/7]
Compute the LU factorization returning the lower and upper triangular matrices and the permutation matrix:
syms a [L, U, P] = lu(sym([0 0 a; a 2 3; 0 a 2]))
L = [ 1, 0, 0] [ 0, 1, 0] [ 0, 0, 1] U = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a] P = [ 0, 1, 0] [ 0, 0, 1] [ 1, 0, 0]
Use the 'vector' flag to return the permutation information as a vector:
syms a A = [0 0 a; a 2 3; 0 a 2]; [L, U, p] = lu(A, 'vector')
L = [ 1, 0, 0] [ 0, 1, 0] [ 0, 0, 1] U = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a] p = [ 2, 3, 1]
Use isAlways to check that A(p,:) = L*U:
isAlways(A(p,:) == L*U)
ans = 1 1 1 1 1 1 1 1 1
Restore the permutation matrix P from the vector p:
P = zeros(3, 3); for i = 1:3 P(i, p(i)) = 1; end P
P = 0 1 0 0 0 1 1 0 0
Compute the LU factorization of this matrix returning the permutation information in the form of two vectors p and q:
syms a A = [a, 2, 3*a; 2*a, 3, 4*a; 4*a, 5, 6*a]; [L, U, p, q] = lu(A, 'vector')
L = [ 1, 0, 0] [ 2, 1, 0] [ 4, 3, 1] U = [ a, 2, 3*a] [ 0, -1, -2*a] [ 0, 0, 0] p = [ 1, 2, 3] q = [ 1, 2, 3]
Use isAlways to check that A(p, q) = L*U:
isAlways(A(p, q) == L*U)
ans = 1 1 1 1 1 1 1 1 1
Compute the LU factorization of this matrix returning the lower and upper triangular matrices, permutation matrices, and the scaling matrix:
syms a A = [0, a; 1/a, 0; 0, 1/5; 0,-1]; [L, U, P, Q, R] = lu(A)
L = [ 1, 0, 0, 0] [ 0, 1, 0, 0] [ 0, 1/(5*a), 1, 0] [ 0, -1/a, 0, 1] U = [ 1/a, 0] [ 0, a] [ 0, 0] [ 0, 0] P = [ 0, 1, 0, 0] [ 1, 0, 0, 0] [ 0, 0, 1, 0] [ 0, 0, 0, 1] Q = [ 1, 0] [ 0, 1] R = [ 1, 0, 0, 0] [ 0, 1, 0, 0] [ 0, 0, 1, 0] [ 0, 0, 0, 1]
Use isAlways to check that P*(R\A)*Q = L*U:
isAlways(P*(R\A)*Q == L*U)
ans = 1 1 1 1 1 1 1 1
Compute the LU factorization of this matrix using the 'vector' flag to return the permutation information as vectors p and q. Also compute the scaling matrix R:
syms a A = [0, a; 1/a, 0; 0, 1/5; 0,-1]; [L, U, p, q, R] = lu(A, 'vector')
L = [ 1, 0, 0, 0] [ 0, 1, 0, 0] [ 0, 1/(5*a), 1, 0] [ 0, -1/a, 0, 1] U = [ 1/a, 0] [ 0, a] [ 0, 0] [ 0, 0] p = [ 2, 1, 3, 4] q = [ 1, 2] R = [ 1, 0, 0, 0] [ 0, 1, 0, 0] [ 0, 0, 1, 0] [ 0, 0, 0, 1]
Use isAlways to check that R(:,p)\A(:,q) = L*U:
isAlways(R(:,p)\A(:,q) == L*U)
ans = 1 1 1 1 1 1 1 1
Call the lu function for this matrix:
syms a A = [0 0 a; a 2 3; 0 a 2]; lu(A)
ans = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a]
Verify that the resulting matrix is equal to U + L - eye(size(A)), where L and U are defined as [L,U,P] = lu(A):
[L,U,P] = lu(A); U + L - eye(size(A))
ans = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a]