# How to get the diagonal elements of a covariance matrix from its sparse precision matrix?

I have a equation to solve $Ax = b$, where $A$ happens to be the precision matrix of a multivariate Gaussian distribution. I can use either direct solver or iterative solvers to get the $x$ vector. However, I also need to get the diagonal elements of the covariance matrix given by $A^{-1}$. I cannot directly invert the sparse precision matrix $A$ since the dimension is very high and its inverse will be full. It won't fit in memory. But I want to get the diagonal elements of the covariance matrix $A^{-1}$. How can I get it?

• Is this related to your question here? stats.stackexchange.com/questions/57468/… In general are you totally positive that there isn't something you are trying solve? Usually getting $A^{-1}$ is a bit hard. If you try to replicate a paper you might as well mention it so we might be able to help more substantially. (Also try the scicomp.stackexchange.com you might be pleasantly surprised.) – usεr11852 Apr 28 '13 at 3:48

Solving with $b =$ the $i$'th column of the identity matrix will make the resulting $x =$ the $i$'th column of the covariance matrix. Do that for $i = 1,\dots,n$, each time keeping only the $i$'th element of $x$.