# How to computationally invert a matrix with small values?

I'm using an affine transformation matrix to map values of magnitude 10e3 (screen) to values of magnitude 10e-15 or less (small parts of fractal sets).

I also need to map the other way round, so I simply inverse the matrix. It works when the magnitudes are not too far appart, but it fails when the determinant gets too close to zero to be represented with standard double numbers.

The matrix I use are of the form:

a c e
b d f
0 0 1


And the inversion algorithm I have is:

var dt = a * d - b * c;
return new Matrix(d/dt, -b/dt, -c/dt, a/dt, (c * f - d * e) / dt, -(a * f - b * e) / dt);


Is there an alternate way of inverting the matrix? I'm not very good at mathematics, so I would need a simple solution, and one I could find the code, or an algorithm, for.

An example of such a matrix:

 3.26091378894248e-9   -1.882689453850103e-9   -0.7172216437740687
-1.882689453814925e-9  -3.2609137888815494e-9  -0.23371832131832268
0                      0                       1


Thank you.

• In general you could use LU decomposition, QR decomposition, or (an expensive) SVD. In case of that particular matrix, you can rescale the rows first. Notice that inverting an ill-conditioned matrix well is ill-conditioned. Commented Mar 3, 2016 at 23:10