View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Nearest positive semi-definite covariance matrix

1.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 5.08 KB File ID: #34182 Version: 1.1
image thumbnail

Nearest positive semi-definite covariance matrix


Marco B. (view profile)


12 Dec 2011 (Updated )

Find nearest positive semi-definite matrix to a symmetric matrix that is not positive semi-definite

| Watch this File

File Information

The function performs a nonlinear, constrained optimization to find a positive semi-definite matrix that is closest (2-norm) to a symmetric matrix that is not positive semi-definite which the user provides to the function. The optimization is subject to the constraint that the output matrix' diagonal elements as well as its eigenvalues are non-negative.


This file inspired Nearest Spd.

Required Products Optimization Toolbox
MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
16 Dec 2013 Martin

Martin (view profile)

Regarding Shuo Han's alternative solution. For robustness I had to modify it to the below. My theory is that the division with V sometimes introduces numerical errors that are large enough to result in a new negative eigenvalue.

[V,D] = eig(A);
A_psd = V * diag(max(diag(D),eps)) / V;

Comment only
20 Sep 2012 Shuo Han

This does not need fmincon() and can be done in two lines. Suppose the input matrix is A

[V,D] = eig(A);
A_psd = V * max(D,0) / V;

12 Dec 2011 1.1

Example input matrix added

Contact us