File Exchange

image thumbnail

Nearest positive semi-definite covariance matrix

version 1.1 (5.08 KB) by

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

2 Downloads

Updated

View License

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.

Comments and Ratings (2)

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;

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;

Updates

1.1

Example input matrix added

MATLAB Release
MATLAB 7.8 (R2009a)
Acknowledgements

Inspired: nearestSPD

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

» Watch video