MATLAB Answers


Preserving positive-definiteness after thresholding and inversion

Asked by firdaus
on 19 May 2013


I'm observing some unexpected behavior in matlab after the following steps:

a) start with a non-definite symmetric matrix X (of n >= 10)

b) do an eigen decomposition of X and set all negative eigenvalues to 0

c) reconstruct X_hat and X_hat_inverse - which should be positive semi-definite.

d) check the eigenvalues of X_hat and X_hat_inverse

Both these matrices sometimes turn out to have negative (albeit very small) values !

Here's some code for that:

X = rand(1000,10);
X = X'*X/1000;
eig(X)  % all positive
X(X(:)<0.25) = 0  % no longer psd
[uu_,dd_] = eig(X);
dd_( dd_(:)<0 ) = 0;
X_hat = uu_*dd_*uu_';
X_hat_inv = uu_*pinv(dd_)*uu_';  
eig(X_hat)   %negative e.v.s !!
eig(X_hat_inv) % complex e.v.s !!!

are these acceptable numerical errors - or is something wrong ?

Thanks -fj



No products are associated with this question.

1 Answer

Answer by the cyclist
on 19 May 2013

The numerical errors here are exactly of the magnitude I expect. You can use the eps() function to help gauge that error.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!