I tried solving this problem on my own but I cant find a proper solution.
I need to evaluate the following equation: $\sum\limits_{m=1\\m\neq i}^n{\left(\dfrac{v_m~(\lambda_i\cdot B-A)~u_i}{(\lambda_m-\lambda_i)\cdot x_m}\right)\cdot u_m-\left(\dfrac{v_i~B~u_i}{2\cdot x_i}\right)\cdot u_i~,~i=1,...,n}$
$A$ and $B$: real non-symmetric matricies
$v_i$: $i$th left-Eigenvector
$u_i$: $i$th right-Eigenvector
$\lambda_i$: $i$th Eigenvalue
The computation time is kinda fast for $n\leq250$ and it gets significantly slower for greater $n$. I need to evaluate this equation for at least $n=500$ and this takes forever. I posted my current "solution" below and would like to ask if there is a chance to speed up this computation.
n = 250;
A = RandomReal[{1*10^-7, 1*10^-6}, {n, n}];
B = RandomReal[{1*10^-12, 1*10^-11}, {n, n}];
X = RandomReal[{1*10^-12, 1*10^-11}, {n}];
{EW, EVR} = Eigensystem[{A, B}];
{EW, EVL} = Eigensystem[{Transpose[A], Transpose[B]}];
ParallelTable[
Sum[If[m == i, 0,
(EVL[[m]].(EW[[i]]*B - A).EVR[[i]])/((EW[[m]] - EW[[i]])*X[[m]])*EVR[[m]]], {m, 1, n}]
- EVR[[i]]*(EVL[[i]].B.EVR[[i]])/(2*X[[i]]), {i, 1, n}];
Thanks in advance.
If[m == I
at every iteration; just iterate over the indices wherem != i
. Generic lesson - don't buryif
statements at the bottom of deep loop nests if they can be lifted out, $\endgroup$