The help file is slightly unclear here, but it doesn't mean that you can just use a non-positive definite matrix and get the same result by changing the way you call the function:
[R,p] = chol(A) for positive definite A, produces an upper triangular
matrix R from the diagonal and upper triangle of matrix A, satisfying
the equation R'*R=A and p is zero. If A is not positive definite, then
p is a positive integer and MATLABĀ® does not generate an error. When A
is full, R is an upper triangular matrix of order q=p-1 such that
R'*R=A(1:q,1:q).
If your matrix is not positive definite, p > 0, therefore the size of your result R will depend on p
. In fact, I think this particular syntax is simply designed to allow you to use chol
as a way of checking if A is positive definite, rather than just giving an error if it is not. The help file even says:
NoteĀ Using chol is preferable to using eig for determining positive definiteness.
Example - take pascal(5)
and set the last element to something negative:
A =
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 -3
[R,p] = chol(A)
returns
R =
1 1 1 1
0 1 2 3
0 0 1 3
0 0 0 1
p =
5
Sure enough, R'*R' == A(1:4,1:4)
By setting element X(2,2)
to be negative, on the other hand, gives p
of 2 and therefore a single value in R
which will be sqrt(A(1,1)
. Setting A(1,1)
to be negative returns p = 1
and an empty R
.