I have some matrix-valued, complex data $Z(f)$ with $f\in\{f_0,f_1,\dots\}$ and $Z(f_i)$ being a 3x3 matrix. I require the inverse $Z^{-1}(f)$ in my workflow. After encountering some problems with my results, I cold narrow the issue down to the inversion, which seems to be performed not very accurately by numpy.linalg.inv and to a lesser extend also by scipy.linalg.inv.
As you can see in the plot of the off-diagonal element $Z_{12}$ below, at intermediate values $10^3<f <10^5$ applying the numpy inversion twice does not yield the original data $Z$. In the plot, the scipy inversion seems to have no issues, but using scipy to compute $Z^{-1}Z$ also does not result exactly in the unity matrix at these values of $f$.
While the condition number of $Z(f)$ diverges for $f\rightarrow 0$ as seen in the second plot below, I would like to understand why my issues can occur at intermediate $f$ values, and how to choose an inversion algorithm that minimizes such problems.
mpmath
. $\endgroup$Zx = b
is better than inverting. $\endgroup$