Does the function chol correctly indicates that a Matrix is positive definite ?
Afficher commentaires plus anciens
According to the MATLAB documentation for the function chol: "[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"
I have found an example contradicting the behavior described so I do not understand if I can trust this function or whether there is an error in the documentation.
Let's have the following Matrix.
A =
[[0.957166948 0.421761283 0.655740699 0.655740699];
[0.485375649 0.915735525 0.035711679 0.035711679];
[0.800280469 0.79220733 0.849129306 0.849129306];
[0.141886339 0.959492426 0.933993248 0.933993248]];
Then the Cholesky factorization gives the following result:
[R,p] = chol(A)
R =
0.9783 0.4311 0.6703 0.6703
0 0.8543 -0.2964 -0.2964
0 0 0.5586 0.5586
0 0 0 0.2913
p =
0
So the p = 0 indicates according to the interpretation I have of the documentation that A is positive definite, which also indicates that the matrix A is nonsingular.
However this matrix is clearly singular given that the last two columns are identical. When computing the eigenvalues I get a zero eigenvalue which confirms this singularity. Also the determinant gives a numerical zero value.
> eig(A)
ans =
2.5108 + 0.0000i
-0.0000 + 0.0000i
0.5726 + 0.3574i
0.5726 - 0.3574i
>> abs(det(A)) < eps
ans =
logical
1
Conclusion: I can not conclude from P=0 in chol that the matrix is Positive definite.
Is there an error in this function, in the documentation or I am missing/misunderstanding something ?
I appreciate your help with this, dear MATLAB users.
Réponse acceptée
Plus de réponses (1)
Thanks John!
I have also encountered this problem when studying "chol()" and luckily found someone else has realized this. What's more, I found that Chol will behave quite differently towards two similar matrices even if we do not consider decimal digits. I have tried some examples and wrote down here. My current version is Matlab r2022a.
The base matrix is just the first example from the Chol help documents.
A = [1 0 1; 0 2 0; 1 0 3]
- 1. If we change the element in A(3,1) to any other number except "1", for instance "1000", Chol will always regard this matrix as positive definite and return "flag = 0"
A1 = [1 0 1; 0 2 0; 1000 0 3]
[R1,flag1] = chol(A1)
- 2. However, if we change the element in A(1,3) to any other number except "1", for instance "2", Chol will always correctly detect non-positive definite matrix and return non-zero values.
A2 = [1 0 2; 0 2 0; 1 0 3]
[R2,flag2] = chol(A2)
4 commentaires
Steven Lord
le 29 Août 2022
This is Not a Bug.
From the first entry in the Description section of the documentation for the chol function: "R = chol(A) factorizes symmetric positive definite matrix A into an upper triangular R that satisfies A = R'*R. If A is nonsymmetric , then chol treats the matrix as symmetric and uses only the diagonal and upper triangle of A." [Emphasis added.]
In your first case you're changing the lower triangular part of A which chol doesn't use. In your second case you're changing the upper triangular part of A which it does.
Zheng
le 29 Août 2022
Thanks Steven.
Yes, I found the description which indicates how it treats a nonsymmetric matrix. However, the thing is that both A1 and A2 are nonsymmetric in my examples, if I am right, while Chol treat them differently. You can also see that from the value of "flag". I am afraid that both of them should be non-zero numbers.
Zheng
le 29 Août 2022
Ah I think I found the reason.
The second example, A2, could not be positive definite under this case even if Chol only uses the upper triangular part of A2. Symmetry is just a necessary condition...
Steven Lord
le 29 Août 2022
if I am right, while Chol treat them differently.
Yes, that is correct and is the correct behavior. The chol function ignores the lower triangular part of the input entirely unless you explicitly specify the second input as 'lower' to tell it to ignore the upper triangular part instead.
From the description of the A input argument in the documentation page to which I linked in my previous comment: "chol assumes that A is symmetric for real matrices or Hermitian for complex matrices. chol uses only the upper or lower triangle of A to perform its computations, depending on the value of triangle." [Emphasis added.]
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!