Code covered by the BSD License

### Highlights from Nearest positive semi-definite covariance matrix

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

# Nearest positive semi-definite covariance matrix

by

### Marco B. (view profile)

12 Dec 2011 (Updated )

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

File Information
Description

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.

Acknowledgements

This file inspired Nearest Spd.

Required Products Optimization Toolbox
MATLAB release MATLAB 7.8 (R2009a)
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

### Shuo Han (view profile)

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;