Hello I'm trying to compute the trace of the product of matrices like this
$$\begin{equation} \begin{pmatrix} a+\imath b &c &0 \\ c& d &c \\ 0& c &f+\imath g \end{pmatrix}^{-1} \begin{pmatrix} -2b &0 &0 \\ 0 & 0 &0 \\ 0& 0 &0 \end{pmatrix} \begin{pmatrix} a+\imath b &c &0 \\ c& d &c \\ 0& c &f+\imath g \end{pmatrix}^{*-1} \begin{pmatrix} 0 &0 &0 \\ 0 & 0 &0 \\ 0& 0 &-2g \end{pmatrix} \end{equation}$$
where $*$ is the comlpex transpose and all the components are real.
This situation is very easy to compute it but if I want to do it for a 50x50 matrix (the first is a tridiagonal matrix with $d$ in the main diagonal except the $(1,1)$ and $(N,N)$ elements, $c$ in the other two diagonals,the second and the forth have non zero elements only in the $(1,1)$ and $(N,N)$ positions) it's almost take a lot of time.
Taking advantage of the symmetry and that at the end only the last column is non zero (and therefore only the element $(N,N)$ will contribute) is there a way to compute it faster?
Thanks
Edit: The code I'm using for a 10x10 matrix is the following
M = {{a + I b, c, 0, 0, 0, 0, 0, 0, 0, 0}, {c, d, c, 0, 0, 0, 0, 0, 0,
0}, {0, c, d, c, 0, 0, 0, 0, 0, 0}, {0, 0, c, d, c, 0, 0, 0, 0,
0}, {0, 0, 0, c, d, c, 0, 0, 0, 0}, {0, 0, 0, 0, c, d, c, 0, 0,
0}, {0, 0, 0, 0, 0, c, d, c, 0, 0}, {0, 0, 0, 0, 0, 0, c, d, c,
0}, {0, 0, 0, 0, 0, 0, 0, c, d, c}, {0, 0, 0, 0, 0, 0, 0, 0, c,
f + I g}};
G1 = {{-2 b, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0,
0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0,
0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0,
0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0}};
G2 = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0,
0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0,
0, -2 g}};
Inverse[M].G1.Inverse[ConjugateTranspose[M]].G2 //ComplexExpand
To make tridiagonal matrices I'm using the comand
SparseArray[{Band[{1, 2}] -> c, Band[{1, 1}] -> d, Band[{2, 1}] -> c},10] // Normal
and then recopying it, change only the two elements I need to change and then I operate