chol

Cholesky factorization of a symmetric positive definite matrix.

Category: Mathematics > Linear Algebra

Syntax

R = chol(A)

Returns the upper triangular R with R'*R = A.

L = chol(A, 'lower')

Returns the lower triangular L with L*L' = A.

[R, p] = chol(A)

Does not raise an error when A is not positive definite; p is 0 on success.

Description

A matrix is positive definite when it is symmetric and all its eigenvalues are positive. Such a matrix factors uniquely as R'*R with R upper triangular and positive diagonal. The factorization takes about half the work of lu and is numerically stable without pivoting.

It solves systems with x = R\(R'\b), tests positive definiteness cheaply (use the two-output form), and generates correlated random numbers from a covariance matrix. With a single output, a matrix that is not positive definite raises an error.

Input arguments

A
Square symmetric (or Hermitian) matrix. Only the upper triangle is read.
'lower'
Option that returns the lower triangular factor.

Output arguments

R
Triangular factor with positive diagonal.
p
0 if A is positive definite; otherwise the index of the failing pivot, and R is the factor of the leading block of order p - 1.

Example

Factor, check, and a failing case

A = [4 2; 2 3];
R = chol(A)
R'*R
L = chol(A, 'lower')
[~, p] = chol([1 2; 2 1])
Output
R = 2×2

    2.0000    1.0000
         0    1.4142
ans = 2×2

    4.0000    2.0000
    2.0000    3.0000
L = 2×2

    2.0000         0
    1.0000    1.4142
p = 2

See also

cholupdate lu ldl qr eig