Error using chol Matrix must be positive definite.

98 views (last 30 days)
I have a positive definite matrix C for which R=chol(C) works well. I want to apply the chol function to a new matrix A = U*C*U' where U is a unitary matrix obtained as output from SVD, i.e. from [V,S,U] = dvd(T); but I get an error telling me that A is not positive definite. I checked that det(U) = 1.0 so I don't understand why the symmetric matrix A is not positive definite.
Given that C is positive definite then y'*C*y>0 and if I let y = U'*x then x'*U*C*U'*x>0 which implies that U*C*U'is also positive definite.
Is this problem due to round off or am I missing some important linear algebra concept. If not is there a way around this problem?
  8 Comments
John D'Errico
John D'Errico on 18 Jun 2016
The most common reason for this is NOT the difference in code, which should not be, but how you pass the array between. Too often people think they can pass an ascii file between the two machines, that this is sufficient.
Unless the array is passed EXACTLY between machines as a .mat file, you are NOT making a proper comparison. Without use of a .mat file, there will be tiny errors in the least significant bits.
Zhiyong Niu
Zhiyong Niu on 10 Nov 2017
Edited: Zhiyong Niu on 10 Nov 2017
The diagnal of a positive definite matrix is real. However, if you obtain A by A = U*C*U' ,the diagnal of A may have imagenary parts, even though they are extremely tiny, on the order of 1e-17i. if so, the chol() may give you an error when the elements of diagnal was checked.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 17 Jun 2014
One solution is to use my nearestSPD code as found on the file exchange. It handles the semi-definite matrix, finding the smallest perturbation into a positive definite matrix, one that will be ASSUREDLY factorizable using chol.
  1 Comment
Junho Kweon
Junho Kweon on 22 Feb 2023
I totally agree with this. Due to the limitation of the computation in MATLAB, sometimes minor computational error cause sight asymmetric or slightly-not-positive-definite matrix. I had same issue with @Francois, but the code as @John D'Errico showed solved this problem very well.

Sign in to comment.

More Answers (1)

Youssef  Khmou
Youssef Khmou on 16 Jun 2014
this an interesting problem,
Generally, the matrix C must contain some negative and positive eigenvalues ( eig(C)) according the description, in the other hand, the matrix A is positive semi definite only if C is diagonal matrix with the diagonal elements being the eigenvalues corresponding the eigenvectors U(:,1),....U(:,N).
In this case you multiply C whether diagonal or not with non corresponding eigenvectors, so A can not be positive semi definite .
  1 Comment
Matt J
Matt J on 17 Jun 2014
Edited: Matt J on 17 Jun 2014
A is positive semi definite only if C is diagonal matrix with the diagonal elements being the eigenvalues corresponding the eigenvectors U(:,1),....U(:,N).
Not true. Suppose U=eye(N). Then A=C and both are positive (semi) definite simultaneously, regardless of whether C is diagonal.

Sign in to comment.

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!