Computes the Cholesky factorization of a square matrix.
CHOLESKY(a, eflag, "triangle")
(C, p) = CHOLESKY(a, eflag, "triangle")
a |
- |
A square matrix. |
||||
eflag |
- |
Optional. An integer, the error report flag:
|
||||
"triangle" |
- |
Optional. A string, the output triangle:
|
An upper or lower triangular matrix, the Cholesky factor of the input matrix.
(C, p)
= CHOLESKY(a, eflag, "triangle") returns both the Cholesky
factor C and p,
the number of Nulls if the input is not positive definite, or 0 if the
input is positive definite. If p
is
a = {{3, 2, 3},
{2, 4, 2},
{3, 2, 4}};
C = cholesky(a);
C == {{1.73205, 1.15470, 1.73205},
{0, 1.63299, -4.07615e-16},
{0, 0, 1}}
Matrix a is positive definite and C represents the Cholesky factor.
conj(C’) *^ C == {{3, 2, 3},
{2, 4, 2},
{3, 2, 4}}
eig(a) == {8.36468, 0.434583, 2.20074}
Because matrix a is positive definite, the eigenvalues of a are all positive.
For any non-zero vector v:
v = {1, 10, -20}
conj(v’) *^ a *^ v == {1123}
also demonstrating that a is positive definite.
a = {{3, 2, 3},
{2, 4, 2},
{3, 2, 4}};
C = cholesky(a, "lower");
C == {{1.73205, 0, 0},
{1.15470, 1.63299, 0},
{1.73205, -4.07615e-16, 1}}
Same as above except the lower triangle is returned.
a = {{3, 2, 3},
{2, 4, 2},
{3, 2, 4}};
(C, p) = cholesky(a);
C == {{1.73205, 1.1547, 1.73205},
{0, 1.63299, -2.71948e-016},
{0, 0, 1}}
p == 0
Same as the first example except the result of p == 0 demonstrates that matrix a is positive definite.
b = {{3, 2, 3},
{2, 4, 2},
{3, 2, 1}};
(C, p) = chol(b);
p > 0 indicating b is not positive definite and C was not fully computed.
eig(b) == {7.44241, -1.21371, 1.7713}
Because matrix b is not positive definite, the eigenvalues of b are not all positive.
conj(v’) *^ b *^ v == {-77}
also demonstrating that b is not positive definite.
Matrix a
is positive definite if
The eigenvalues of a positive definite matrix are all positive.
For a positive definite matrix a, the Cholesky factor C is an upper triangular matrix such that:
conj(C’) *^ C == a
If the input matrix is not positive definite,
an error results unless eflag is 1.
However, for
CHOLESKY can be abbreviated CHOL.
See DADiSP/MatrixXL to significantly optimize CHOLESKY.