2
$\begingroup$

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)$.

$\endgroup$
14
  • 1
    $\begingroup$ @Vsevolod, which changes the question to "what's a fast way to get the diagonal of the adjoint?". $\endgroup$ Mar 26, 2018 at 5:02
  • 2
    $\begingroup$ Does your matrix have anything special about it (sparse, symmetric, etc.)? $\endgroup$ Mar 26, 2018 at 5:03
  • 1
    $\begingroup$ While finding the adjoint of a matrix is not built-in, it seems to be defined in the Applications section of Minors. Not sure if it is the way to go though. $\endgroup$
    – Kiro
    Mar 26, 2018 at 5:23
  • 1
    $\begingroup$ The complexity of Cramer's rule for all diagonal elements of the inverse of a general, dense $n \times n$ matrix A is n (n-1)^(n-1) + n^n while LU-decomposition has complexity n^3. The latter can be obtained with Diagonal[LinearSolve[A, IdentityMatrix[n, SparseArray]]]. $\endgroup$ Mar 26, 2018 at 8:56
  • 1
    $\begingroup$ But quite surprisingly, Diagonal[Inverse[A]] is faster... (n = 1000) $\endgroup$ Mar 26, 2018 at 9:01

1 Answer 1

1
$\begingroup$

Proceed a similar way like @Vsevolod A. proposed.

Calculate the determinant of the submatrix of diagonal elements of the original matrix and divide by the total determinant.

subm[A_, diapos_] := Drop[A, {diapos}, {diapos}]

dialist[A_] := Table[Det[subm[A, pos]], {pos, 1, First@Dimensions[A]}]/Det[A]

Here the proof.

dialist[Array[Subscript[a, ##] &, {3, 3}]] == 
   Diagonal[Inverse[Array[Subscript[a, ##] &, {3, 3}]]]

(*   True   *)

dialist[Array[Subscript[a, ##] &, {8, 8}]] == 
   Diagonal[Inverse[Array[Subscript[a, ##] &, {8, 8}]]]

(*   True   *)
$\endgroup$
1
  • 2
    $\begingroup$ Thanks, unfortunately this appears to be quite a bit slower for my purpose compared to simply inverting the matrix. I have added some detail to the question, I don't know if it will help to find a faster solution. $\endgroup$
    – Kai
    Mar 26, 2018 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.