chol

Cholesky factorization

描述

例子

r=chol(一个factorizes symmetric positive definite matrix一个上三角形r满足a =r'*r。如果一个是非对称的,然后choltreats the matrix as symmetric and uses only the diagonal and upper triangle of一个

例子

r=chol(一个,,,,三角形指定哪个三角因素的一个用于计算分解。例如,如果三角形'lower', 然后chol仅使用对角线和下三角部分一个to produce a lower triangular matrixr满足a =r*R'。的默认值三角形'上'

例子

[[r,,,,旗帜] = chol(___also returns the output旗帜指示是否一个对称阳性确定。您可以在先前的语法中使用任何输入参数组合。指定旗帜输出,choldoes not generate an error if the input matrix is not symmetric positive definite.

  • 如果旗帜=0then the input matrix is symmetric positive definite and the factorization was successful.

  • 如果旗帜不是零,那么输入矩阵是not对称阳性确定and旗帜是an integer indicating the index of the pivot position where the factorization failed.

例子

[[r,,,,旗帜,,,,p] = chol(s另外返回置换矩阵p,这是稀疏矩阵的预订s获得amd。如果旗帜=0, 然后s是对称的积极确定的,并且r是一个令人满意的上三角矩阵r'*r = p'*s*p

例子

[[r,,,,旗帜,,,,p] = chol(___,,,,输出形式specifies whether to return the permutation informationp作为矩阵或向量,使用先前语法中的任何输入参数组合。此选项仅用于稀疏矩阵输入。例如,如果输出形式'vector'and旗帜=0, 然后s(p,p)= r'*r。的默认值输出形式'matrix'such thatr'*r = p'*s*p

例子

全部收缩

利用chol分解对称系数矩阵,然后使用Cholesky因子求解线性系统。

在对角线上创建一个具有正值的对称矩阵。

a = [1 0 1;0 2 0;1 0 3]
a =3×31 0 1 0 2 0 1 0 3

Calculate the Cholesky factor of the matrix.

r = chol(a)
r =3×31.0000 0 1.0000 0 1.4142 0 0 0 1.4142

为方程的右侧创建向量 斧头 = b

b=sum(A,2);

自从 一个 = r t r 和the Cholesky decomposition, the linear equation becomes r t r X = b 。解决X使用Backslash操作员。

x = r \(r'\ b)
X=3×11.0000 1.0000 1.0000

计算矩阵的上和下cholesky因素化并验证结果。

Create a 6-by-6 symmetric positive definite test matrix using the画廊功能。

a =画廊('莱默',6);

Calculate the Cholesky factor using the upper triangle of一个

r = chol(a)
r =6×61.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0 0.8660 0.5774 0.4330 0.3464 0.2887 0 0 0.7454 0.5590 0.4472 0.3727 0 0 0 0.6614 0.5292 0.4410 0 0 0 0 0.6000 0.5000 0 0 0 0 0 0.5528

验证上三角因子满足r'*r- A = 0,,,,和in roundoff error.

norm(r'*r -a)
ANS = 2.8886e-16

现在,指定'lower'使用下部三角形计算cholesky因子的选项一个

l = chol(a,'lower'
l =6×61.0000 0 0 0 0 0 0.5000 0.8660 0 0 0 0 0.3333 0.5774 0.7454 0 0 0 0.2500 0.4330 0.5590 0.6614 0 0 0.2000 0.3464 0.4472 0.5292 0.6000 0 0.1667 0.2887 0.3727 0.4410 0.5000 0.5528

验证下部三角因子是否满足l*l' - a = 0,,,,和in roundoff error.

norm(l*l' -  a)
ans =2.1158e-16

利用chol当输入矩阵不是对称正定确定时,有两个输出可以抑制误差。

创建一个5 x-5的二项式系数矩阵。该矩阵是对称的阳性确定性的,因此从最后一个元素中减去1,以确保其不再是正定义。

a =pascal(5); A(end) = A(end) - 1
a =5×51 1 1 1 1 1 1 2 3 4 5 1 3 6 10 15 1 4 10 20 35 1 5 15 35 69

计算Cholesky因子一个。指定两个输出,以避免产生错误一个不是对称的阳性确定性。

[[r,,,,旗帜] = chol(一个)
r =4×41 1 1 1 0 1 2 3 0 0 1 3 0 0 0 1
旗帜=5

自从旗帜是非零的,它给出了分解失败的枢轴索引。chol能够计算q = flag-1=4行和列在遇到更改的矩阵的一部分时正确之前正确的行和列。

验证这一点r'*r返回四行和列a(1:q,1:q)

q = flag-1;r'*r
ans =4×41 1 1 1 1 2 3 4 1 3 6 10 1 4 10 20
a(1:q,1:q)
ans =4×41 1 1 1 1 2 3 4 1 3 6 10 1 4 10 20

计算稀疏矩阵的Cholesky因子,并使用置换输出来创建较少的nonzeros的Cholesky因子。

基于West0479矩阵。

加载West0479a = west0479;s = a'*a;

计算矩阵的Cholesky因子两种不同的方式。首先指定两个输出,然后指定三个输出以启用行和列重新排序。

[[r,,,,旗帜] = chol(s);[[rp,,,,flagP,P] = chol(S);

对于每个计算,请检查旗帜=0确认计算成功。

如果〜FLAG && 〜FLAGP DISP(“因解成功。”别的disp('Factorizations failed.'结尾
Factorizations successful.

比较在chol(S)vs. the reordered matrixchol(p'*s*p)。best practice is to use the three output syntax ofchol和sparse matrices, since reordering the rows and columns can greatly reduce the number of nonzeros in the Cholesky factor.

子图(1,2,1)间谍(R)标题(R)标题('chol中的nonzeros'')子图(1,2,2)间谍(RP)标题(RP)标题('Nonzeros in chol(P''*S*P)'

使用'vector'选项cholto return the permutation information as a vector rather than a matrix.

Create a sparse finite element matrix.

s =画廊('Wathen',,,,10,10); spy(S)

计算Cholesky因子the matrix, and specify the'vector'返回排列矢量的选项p

[r,flag,p] = chol(s,'vector');

验证这一点旗帜=0,,,,indicating the calculation is successful.

如果〜标志disp(“分解成功。”别的disp('Factorization failed.'结尾
Factorization successful.

验证这一点s(p,p)= r'*r,,,,和in roundoff error.

norm(S(p,p) - R'*R,'fro'
ANS = 2.1039E-13

输入参数

全部收缩

输入矩阵。争论一个can use full or sparse storage, but must be square and symmetric positive definite.

chol假设一个对于真正的矩阵或复杂矩阵的遗传学是对称的。choluses only the upper or lower triangle of一个to perform its computations, depending on the value of三角形

Data Types:single|双倍的
复杂的数字支持:万博1manbetxYes

稀疏输入矩阵。s必须是正方形和对称的正定确定性。

chol假设s对于真正的矩阵或复杂矩阵的遗传学是对称的。choluses only the upper or lower triangle ofsto perform its computations, depending on the value of三角形

Data Types:双倍的
复杂的数字支持:万博1manbetxYes

输入矩阵的三角因子,指定为'上'or'lower'。使用此选项指定cholshould use the upper or lower triangle of the input matrix to compute the factorization.chol假设the input matrix is symmetric for real matrices or Hermitian for complex matrices.choluses only the upper or lower triangle to perform its computations.

Using the'lower'选项等同于调用chol和the'上'选项和输入矩阵的转置,然后转移输出r

例子:r = chol(a,''')

排列输出的形状,指定为'matrix'or'vector'。此标志控制排列是否输出p是returned as a permutation matrix or permutation vector.

  • 如果旗帜=0, 然后s是对称的积极确定的,并且p'*s*p = r'*r(如果p是矩阵)或s(p,p)= r'*r(如果p是a vector).

  • 如果旗帜不是零,那s不是对称的阳性确定性。r是一个大小的上三角矩阵-经过-n,,,,whereq = flag-1。第一个的L形区域排和第一columns ofr'*r同意那些p'*s*p(如果p是矩阵)或S(P,P)(如果p是a vector).

  • 如果是'lower'指定选项,然后r是a lower triangular matrix and you can replacer'*rr*R'在以前的身份中。

Cholesky因素p'*s*p(如果p是矩阵)或S(P,P)(如果p是一个矢量)往往比cholesky因子稀疏s

例子:[r,flag,p] = chol(s,'vector')

Output Arguments

全部收缩

Cholesky factor, returned as a matrix.

  • 如果r是upper triangular, thena =r'*r。如果you specify thep稀疏矩阵的输出,然后p'*s*p = r'*rors(p,p)= r'*r,,,,depending on the value of输出形式

  • 如果r是较低的三角形,然后a =r*R'。如果you specify thep稀疏矩阵的输出,然后p'*s*p = r*r'ors(p,p)= r*r',,,,depending on the value of输出形式。。

  • Whenever旗帜是not zero,r仅包含部分结果。旗帜指示分解失败的枢轴位置,并且r包含部分完成的分解。

对称正定标志,返回标量。

  • 如果旗帜=0,然后输入矩阵为对称阳性确定。r是上三角矩阵r'*r=一个

  • 如果一个不是对称的积极确定的旗帜是一个正整数,指示分解失败的枢轴位置,MATLAB®does not generate an error.r是一个大小的上三角矩阵q = flag-1such thatr'*r = a(1:q,1:q)

  • 如果一个是sparse, thenr是一个大小的上三角矩阵-经过-nsuch that the L-shaped region of the first排和第一columns ofr'*r同意那些一个ors

  • 如果是'lower'指定选项,然后r是a lower triangular matrix and you can replacer'*rr*R'在以前的身份中。

permutation for sparse matrices, returned as a matrix or vector depending on the value of输出形式。看输出形式for a description of the identities that this output satisfies.

this permutation matrix is based on the approximate minimum degree ordering computed byamd。However, this preordering can differ from the one obtained directly byamdsincechol稍微改变了提高性能的顺序。

更多关于

全部收缩

对称阳性确定矩阵

一个对称阳性确定矩阵是具有所有正征值的对称矩阵。

对于任何真实的可逆矩阵一个,,,,you can construct a symmetric positive definite matrix with the productb=一个'*A。Cholesky的分解化可以通过说任何对称阳性矩阵来逆转此公式bcan be factored into the productr'*r

一个对称阳性半明确矩阵的定义类似,除了特征值必须全部为正或零。

在数字计算的背景下,正确定和阳性半明确矩阵之间的界线是模糊的。特征值很少完全等于零,但是在数值上可以为零(在机器精度的顺序上)。为此原因,chol可能能够分解一个阳性半明确矩阵,但是另一个具有非常相似特征值的矩阵可能会失败。

提示

Extended Capabilities

也可以看看

|||

Introduced before R2006a