Since inverting a matrix is often a bad idea, I am wondering if there is a better way to get just the diagonal of the inverse without inverting the whole thing. Note I need the whole diagonal, not the trace. For my application I need to compute the sums of pairs of terms on the diagonal (I'm not sure if there's a name for this, clearly not the same thing as the partial trace).
Edit:
If it makes a difference, the matrix is Hermitian. It has nonzero elements in the first three bands off the main diagonal, and ranges from 8×8 to 40×40. I'm also working with other matrices that have a similar form
$$\begin{pmatrix} 2 & 2\,c_{xy} & e^{-ix/4} & e^{-iy/4} & 0 & 0 & 0 & 0 \\[4pt] 2\,c_{xy} & 2 & e^{iy/4} & e^{ix/4} & 0 & 0 & 0 & 0 \\[4pt] e^{ix/4} & e^{-iy/4} & 2 & 2\,c_{xy} & e^{-ix/4} & e^{iy/4} & 0 & 0 \\[4pt] e^{iy/4} & e^{-ix/4} & 2\,c_{xy} & 2 & e^{-iy/4} & e^{ix/4} & 0 & 0\\[4pt] 0 & 0 & e^{ix/4} & e^{iy/4} & 2 & 2\,c_{xy} & e^{-ix/4} & e^{-iy/4} \\[4pt] 0 & 0 & e^{-iy/4} & e^{-ix/4} & 2\,c_{xy} & 2 & e^{iy/4} & e^{ix/4} \\[4pt] 0 & 0 & 0 & 0 & e^{ix/4} & e^{-iy/4} & 2 & 2\,c_{xy} \\[4pt] 0 & 0 & 0 & 0 & e^{iy/4} & e^{-ix/4} & 2\,c_{xy} & 2 \end{pmatrix}$$
where $c_{xy} = \cos\left(\frac{x+y}{4}\right)$.
Minors
. Not sure if it is the way to go though. $\endgroup$A
isn (n-1)^(n-1) + n^n
while LU-decomposition has complexityn^3
. The latter can be obtained withDiagonal[LinearSolve[A, IdentityMatrix[n, SparseArray]]]
. $\endgroup$Diagonal[Inverse[A]]
is faster... (n = 1000
) $\endgroup$