主要内容

LU factorization

Description

example

[l,u] = lu(一种)返回一个上三角矩阵U和a matrixL,这样a = l * u。这里,Lis a product of the inverse of the permutation matrix and a lower triangular matrix.

example

[L,U,P] = lu(一种)返回一个上三角矩阵U, a lower triangular matrixL,以及置换矩阵P,这样P*A = L*U。语法鲁(一种,'matrix')is identical.

example

[L,U,p] = lu(一种,'vector')将置换信息作为向量返回p,这样一种(p,:) = L*U

example

[L,U,p,q] = lu(一种,'vector')将置换信息作为两行向量返回pq,这样一种(p,q) = L*U

example

[L,U,P,Q,R] = lu(一种)返回一个上三角矩阵U, a lower triangular matrixL,排列矩阵PQ,和一个缩放矩阵R,这样P*(R\A)*Q = L*U。语法鲁(一种,'matrix')is identical.

example

[L,U,p,q,R] = lu(一种,'vector')在两个行向量中返回置换信息pq,这样R(:,p)\A(:,q) = L*U

example

鲁(一种)返回包含严格较低三角形矩阵的矩阵L(没有其单位对角线的矩阵)和上三角矩阵U作为子曲线。从而,鲁(a)returns the matrixU + L - eye(size(A)), whereLUare defined as[l,u,p] = lu(a)。The matrix一种must be square.

Examples

collapse all

Compute the LU factorization of this matrix. Because the numbers are not symbolic objects, you get floating-point results.

m = [2 -3 -1;1/2 1 -1;0 1 -1];[l,u] = lu(m)
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.

m = sym(m);[l,u] = lu(m)
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]

Return the lower and upper triangular matrices and the permutation matrix by providing three output arguments.

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

Return the permutation information as a vector by using the'vector'旗。

Syms A = [0 0 a;一个2 3;0 a 2];[l,u,p] = lu(a,'矢量')
L = (1,0,0) [0, 1,0] [0, 0, 1] U = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a] p = 2 3 1

检查一下一种(p,:) = L*Uby usingisAlways

Isalways(a(p,:) == l * u)
ans = 3×3 logical array 1 1 1 1 1 1 1 1 1

恢复排列矩阵Pfrom the vectorp

p =零(3,3);对于i = 1:3 p(i,p(i))= 1;结束P.
P = 0 1 0 0 0 1 1 0 0

Return the permutation information as two vectorspq

syms a = [a,2,3 * a;2 * a,3,4 * a;4 * a,5,6 * a];[l,u,p,q] = lu(a,'矢量')
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

检查一下一种(p, q) = L*Uby usingisAlways

isAlways(A(p, q) == L*U)
ans = 3×3 logical array 1 1 1 1 1 1 1 1 1

Return the lower and upper triangular matrices, permutation matrices, and scaling matrix.

syms 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]

检查一下P*(R\A)*Q = L*Uby usingisAlways

isAlways(P*(R\A)*Q == L*U)
ans = 4×2 logical array 1 1 1 1 1 1 1 1

Return the permutation information as vectorspqby using the'vector'旗。一种lso, compute the scaling matrixR

syms 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] 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]

检查一下R(:,p)\A(:,q) = L*Uby usingisAlways

isAlways(R(:,p)\A(:,q) == L*U)
ans = 4×2 logical array 1 1 1 1 1 1 1 1

通过指定一个或没有输出参数将三角矩阵作为子群。

Syms A = [0 0 a;一个2 3;0 a 2];鲁(a)
ans = [ a, 2, 3] [ 0, a, 2] [ 0, 0, a]

Verify that the resulting matrix is equal toU + L - eye(size(A)), whereLUare 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]

输入一种rguments

collapse all

输入, specified as a numeric or symbolic matrix.

More About

collapse all

LU Factorization of a Matrix

LU factorization expresses anm-通过-nmatrix一种asP* A=L *U。这里,Lis anm-通过-mlower triangular matrix,Uis anm-通过-n上三角矩阵,和P是一个置换矩阵。

排列载体

The permutation vectorpcontains numbers corresponding to row exchanges in the matrix一种。For anm-通过-mmatrix,prepresents the following permutation matrix with indicesij从1到m

P i j = δ. p i , j = { 1 if j = p i 0 if j p i

提示

  • Callingfor numeric arguments that are not symbolic objects invokes the MATLAB®function.

  • The阈值option supported by the MATLAB功能不会影响符号输入。

  • If you use'matrix'instead of'vector', thenreturns permutation matrices, as it does by default.

  • LUare nonsingular if and only if一种is nonsingular.还可以计算单数矩阵的LU分解一种。在这种情况下,L要么Uis a singular matrix.

  • Most algorithms for computing LU factorization are variants of Gaussian elimination.

在R2013A介绍