What is the best way to constrain a matrix to be positive definite ?
Show older comments
I understand a couple of ways to test whether a matrix, call it p, is positive definite: check eigenvalues, or use [~,tmp] = chol(p).
In my situation, p is part of the solution to an optimization problem for which part of the the nonlinear inequality constraints is that p be positive definite. Ideally, I would like to Specify Constraint Gradient as well, since the other parts of the constraints for this problem benefit significantly from specifying their gradients. Does anyone have an idea how to do this?
3 Comments
Brendan Hamm
on 3 Jan 2017
Disclaimer: I have not actually done this in the past, but the below seems reasonable to me at a first glance.
I would think that you might be better off having your design variables be the elements of the Triangular matrix formed from the Cholesky decomposition. That is rather than having each element of A, you need only optimize over the lower triangular matrix L such that A = L*L'; which would allow you to construct the full matrix in whatever part of the solution you need it. On L you would no longer have any non-linear constraints but rather a strictly positive constraint on the diagonal elements.
One issue that I could see encountering is that the resulting matrix may be near singular due to round off error.
John Terilla
on 6 Jan 2017
Yes. It is true that a good way to constrain a matrix to be numerically SPD is to work with a triangular matrix instead. However, that does not insure the resulting product is always numerically positive definite. For example...
n = 50;
T = tril(rand(n),-1) + diag(repmat(1e-8,n,1));
Clearly, T is a valid triangular matrix. The lower triangle is surely sufficient to make T*T' spd, right?
A = T*T';
all(A == A','all')
It is symmetric. But it is only at best non-negative definite. And some of the time, I'd bet that if you computed the eigenvalues of A, you would see some tiny negative ones appear.
chol(A)
The chol test failed here, which in MATLAB is what most tools use to decide if a matrix is positive definite.
So, while this is a good way to do the job, it still has its limits.
Accepted Answer
More Answers (1)
Nick
on 5 Sep 2025
0 votes
I agree with the other posts. There are multiple ways you can parameterize your positive definite matrix though with some offering potentially more benefits over others. For instance, you can use eigendecomposition to parameterize your matrix in terms of a diagonal matrix of eigenvalues,
, and then an orthogonal matrix of eigenvectors, Q such that
, i.e.,
. Then, to ensure it is positive definite you just need to ensure the elements of Λ are positive definite.
, and then an orthogonal matrix of eigenvectors, Q such that The diagonal eigenvalue matrix is trivial to parameterize but there are many ways to parameterize the orthogonal eigenvector matrix. See this journal paper regarding different parameterizations of orthogonal matrices. It offers some good insight into the differences between each in terms of, for example, computation of each in terms of operation counts. Additionally see this arxiv paper (soon to be published... hopefully) for this eigendecomposition parameterization applied to an optimization problem. However, as far as I am aware, the benefits of one parameterization over another in regards to optimizing a positive definite matrix are unexplored.
As far as ensuring your positive definite matrix is actually positive definite, it will depend on the bounds you set for your eigenvalues. These bounds might take some trial and error to set depending on your problem. I know the original question is quite old at this point, but are you able to share details of the optimization problem you were trying to solve? I am curious what kinds of applications this problem might arise in other than one in the arxiv paper I linked.
Categories
Find more on Operating on Diagonal Matrices 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!