# [R] how to invert the matrix with quite small eigenvalues

huang min minhuangr at gmail.com
Mon May 30 09:20:56 CEST 2005

```Dear all,

I encounter some covariance matrix with quite small eigenvalues
(around 1e-18), which are smaller than the machine precision. The
dimension of my matrix is 17. Here I just fake some small matrix for
illustration.

a<-diag(c(rep(3,4),1e-18)) # a matrix with small eigenvalues
b<-matrix(1:25,ncol=5) # define b to get an orthogonal matrix
b<-b+t(b)
bb<-eigen(b,symmetric=T)
aah<-bb\$vectors%*%diag(1/sqrt(diag(a)))
aa<-aah%*%t(aah) # aa should have the same eigenvalues as a and
should be #invertable,however,
solve(aa) # can not be solved
solve(aa,tol=1e-19) # can be inverted, however, it is not symmetric
and furthermore,
solve(aa,tol=1e-19)%*%aa # deviate much from the identity matrix

I have already define aa to make sure it is symmetric. So the inverse
should be symmetric.

Does the problem come from the rounding error since the eigenvalue is
smaller than the machine precision? In fact, the eigenvalue of aa is
negative now, but at least, it is still invertable. How can I get the
inverse? Thanks.

```